mirror of
https://github.com/JonasunderscoreJones/api-worker.git
synced 2025-10-22 18:09:19 +02:00
Fixed url parameter issue
Fixed an issue where the url parameters weren't getting passed through to the someapi.jonasjones.dev endpoint
This commit is contained in:
parent
3db9932e7a
commit
cbf9bac60e
1 changed files with 6 additions and 6 deletions
12
src/index.js
12
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue