Skip to content

Instantly share code, notes, and snippets.

@sandeep1995
Created June 30, 2022 11:51
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 sandeep1995/aa7d109444224e2387a70d6583123a2e to your computer and use it in GitHub Desktop.
Save sandeep1995/aa7d109444224e2387a70d6583123a2e to your computer and use it in GitHub Desktop.
Docswrite.com blogs sub directory /blog hosting using Cloudflare workers
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