Created
April 25, 2021 16:39
-
-
Save Erisa/4648d28165f4c2d4877400461c6358c6 to your computer and use it in GitHub Desktop.
updown.io status page proxy for cf workers
This file contains hidden or 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