Created
September 29, 2022 08:33
-
-
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.
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
Thanks for this Sandeep!