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 => {
|
addEventListener('fetch', event => {
|
||||||
event.respondWith(handleRequest(event.request));
|
event.respondWith(handleRequest(event.request));
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleRequest(request) {
|
async function handleRequest(request) {
|
||||||
const { pathname, search } = new URL(request.url);
|
const { pathname, search } = new URL(request.url);
|
||||||
|
|
||||||
// List of built-in paths that should not trigger an error
|
// List of built-in paths that should not trigger an error
|
||||||
const allowedPaths = ['/health', '/status'];
|
const allowedPaths = ['/health', '/status'];
|
||||||
|
|
||||||
// if (allowedPaths.includes(pathname)) {
|
// if (allowedPaths.includes(pathname)) {
|
||||||
// // Allow requests to built-in paths
|
// // Allow requests to built-in paths
|
||||||
// return fetch(request);
|
// return fetch(request);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Make a request to someapi.jonasjones.dev/[PATH] including URL parameters
|
// Make a request to someapi.jonasjones.dev/[PATH] including URL parameters
|
||||||
const apiUrl = `https://someapi.jonasjones.dev${pathname}${search}`;
|
const apiUrl = `https://someapi.jonasjones.dev${pathname}${search}`;
|
||||||
const apiRequest = new Request(apiUrl, {
|
const apiRequest = new Request(apiUrl, {
|
||||||
|
@ -20,10 +20,10 @@ addEventListener('fetch', event => {
|
||||||
headers: request.headers,
|
headers: request.headers,
|
||||||
body: request.body
|
body: request.body
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const apiResponse = await fetch(apiRequest);
|
const apiResponse = await fetch(apiRequest);
|
||||||
|
|
||||||
if (apiResponse.status === 502 || apiResponse.status === 530) {
|
if (apiResponse.status === 502 || apiResponse.status === 530) {
|
||||||
// If the API request fails, return an error response
|
// If the API request fails, return an error response
|
||||||
return new Response('Service Unavailable', {
|
return new Response('Service Unavailable', {
|
||||||
|
@ -42,4 +42,3 @@ addEventListener('fetch', event => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue