Skip to content

Instantly share code, notes, and snippets.

@sandeep1995
Created September 29, 2022 08:33
Show Gist options
  • Save sandeep1995/1892457dc2bb718f784126d4fdd2429f to your computer and use it in GitHub Desktop.
Save sandeep1995/1892457dc2bb718f784126d4fdd2429f to your computer and use it in GitHub Desktop.
DocsWrite Complete Blogging Platform on top of Google Docs. This small code shows how to have the blog running at `/blog` using Cloudflare worker.
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);
}
}
@jasonleow
Copy link

Thanks for this Sandeep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment