updown.io status page proxy for cf workers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
async function handleRequest(request) { | |
var whitelist = [ | |
"/rik1", | |
// etc | |
] | |
var url = new URL(request.url); | |
url.hostname = "updown.io" | |
if (url.pathname == "/" || url.pathname == "") | |
{ | |
url.pathname = "/p/xxxxx" + url.pathname | |
} | |
else if (!whitelist.includes(url.pathname)) | |
{ | |
return new Response( | |
JSON.stringify( | |
{ | |
code: '404 Not Found', | |
message: 'Page was not found. I am too lazy to write HTML for this Worker.', | |
}, | |
null, | |
2, | |
), | |
{ | |
status: 404, | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
}, | |
) | |
} | |
return fetch(url, request) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment