Skip to content

Instantly share code, notes, and snippets.

@Erisa
Created April 25, 2021 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erisa/4648d28165f4c2d4877400461c6358c6 to your computer and use it in GitHub Desktop.
Save Erisa/4648d28165f4c2d4877400461c6358c6 to your computer and use it in GitHub Desktop.
updown.io status page proxy for cf workers
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