Last active
May 27, 2022 05:51
-
-
Save VishalTaj/9ae12db1756447e4c5ae3533bd396fe0 to your computer and use it in GitHub Desktop.
Cloudflare Worker to rewrite the response
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
async function handleRequest(req) { | |
const res = await fetch(req) | |
if (res.status == 404) { | |
let init = {...res}; | |
init.status = 200; | |
init.statusText = "OK"; | |
init.webSocket = init.webSocket || undefined; | |
let response = await (new Response(res.body, init)) | |
console.log('overwrite status', response.status) | |
return response | |
} | |
return res | |
} | |
addEventListener("fetch", event => { | |
event.respondWith(handleRequest(event.request)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment