Created
June 30, 2022 11:51
-
-
Save sandeep1995/aa7d109444224e2387a70d6583123a2e to your computer and use it in GitHub Desktop.
Docswrite.com blogs sub directory /blog hosting using Cloudflare 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).catch( | |
(err) => new Response(err.stack, { status: 500 }) | |
) | |
); | |
}); | |
async function handleRequest(request) { | |
let url = new URL(request.url); | |
if (url.pathname.startsWith('/blog')) { | |
url.hostname = "blog.docswrite.blog"; | |
url.pathname = url.pathname.replace('/blog', ''); | |
return fetch(url, request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment