mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-22 19:59:17 +02:00
Added /status for independant api uptime status
This commit is contained in:
parent
ab6bc04c01
commit
a37baf6736
1 changed files with 17 additions and 3 deletions
20
src/index.js
20
src/index.js
|
@ -24,6 +24,19 @@ addEventListener('fetch', event => {
|
|||
try {
|
||||
const apiResponse = await fetch(apiRequest);
|
||||
|
||||
if (pathname === '/status' && apiResponse.ok) {
|
||||
// If the request is to the /status path and the API request is successful, return a custom response
|
||||
return new Response('API is up and running', {
|
||||
status: 200,
|
||||
statusText: 'OK'
|
||||
})} else if (pathname === '/status' && !apiResponse.ok) {
|
||||
// If the request is to the /status path and the API request fails, return a custom response
|
||||
return new Response('API is down', {
|
||||
status: 503,
|
||||
statusText: 'Service Unavailable'
|
||||
})};
|
||||
|
||||
|
||||
if (apiResponse.status === 502 || apiResponse.status === 530) {
|
||||
// If the API request fails, return an error response
|
||||
return new Response('Service Unavailable', {
|
||||
|
@ -35,10 +48,11 @@ addEventListener('fetch', event => {
|
|||
return apiResponse;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// If an error occurs during the API request, return an error response
|
||||
return new Response('API backend is down temporarily', {
|
||||
status: 420,
|
||||
statusText: 'API Backend Downtime Error'
|
||||
return new Response('Internal Server Error', {
|
||||
status: 500,
|
||||
statusText: 'Internal Server Error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue