mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-22 19:59:17 +02:00
Fixed whitespaces
This commit is contained in:
parent
46a7fc6ae3
commit
ab6bc04c01
1 changed files with 6 additions and 7 deletions
13
src/index.js
13
src/index.js
|
@ -1,18 +1,18 @@
|
|||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request));
|
||||
});
|
||||
|
||||
|
||||
async function handleRequest(request) {
|
||||
const { pathname, search } = new URL(request.url);
|
||||
|
||||
|
||||
// List of built-in paths that should not trigger an error
|
||||
const allowedPaths = ['/health', '/status'];
|
||||
|
||||
|
||||
// if (allowedPaths.includes(pathname)) {
|
||||
// // Allow requests to built-in paths
|
||||
// return fetch(request);
|
||||
// }
|
||||
|
||||
|
||||
// Make a request to someapi.jonasjones.dev/[PATH] including URL parameters
|
||||
const apiUrl = `https://someapi.jonasjones.dev${pathname}${search}`;
|
||||
const apiRequest = new Request(apiUrl, {
|
||||
|
@ -20,10 +20,10 @@ addEventListener('fetch', event => {
|
|||
headers: request.headers,
|
||||
body: request.body
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
const apiResponse = await fetch(apiRequest);
|
||||
|
||||
|
||||
if (apiResponse.status === 502 || apiResponse.status === 530) {
|
||||
// If the API request fails, return an error response
|
||||
return new Response('Service Unavailable', {
|
||||
|
@ -42,4 +42,3 @@ addEventListener('fetch', event => {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue