diff --git a/src/index.js b/src/index.js index c033d03..c7ef22e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,9 @@ addEventListener('fetch', event => { - event.respondWith(handleRequest(event.request)) - }) + event.respondWith(handleRequest(event.request)); + }); async function handleRequest(request) { - const { pathname } = new URL(request.url); + const { pathname, search } = new URL(request.url); // List of built-in paths that should not trigger an error const allowedPaths = ['/health', '/status']; @@ -13,8 +13,8 @@ addEventListener('fetch', event => { // return fetch(request); // } - // Make a request to someapi.jonasjones.dev/[PATH] - const apiUrl = `https://someapi.jonasjones.dev${pathname}`; + // Make a request to someapi.jonasjones.dev/[PATH] including URL parameters + const apiUrl = `https://someapi.jonasjones.dev${pathname}${search}`; const apiRequest = new Request(apiUrl, { method: request.method, headers: request.headers, @@ -33,7 +33,7 @@ addEventListener('fetch', event => { status: 420, statusText: 'API Backend Downtime Error' }); - } else if (apiResponse.status === 530) { + } else if (apiResponse.status === 530) { // If the API request fails, return an error response return new Response('API backend went down just now :( It should be back up in a matter of seconds!', { status: 421,