All Collections
Personal websites
William Channel
Using your own domain 🌐
William - Reverse-proxy your Wiliam Blog: Cloudflare example
William - Reverse-proxy your Wiliam Blog: Cloudflare example

Cloudflare example showing how you can reverse proxy your William blog.

Gregory Claeyssens avatar
Written by Gregory Claeyssens
Updated over a week ago

⚠️ Caution: The following article assumes technical knowledge of webservers and related concepts and terminology.

In most organizations, the person who can perform the steps described in this article will be a web administrator (or similar).

This guide also assumes that you have reverse proxy capability available and set up on your website.

See this article for a general overview of reverse proxying your William blog.


Check out the Cloudflare example

Step 1. Create a worker

On Cloudflare navigate to the workers tab and create a new worker.

Step 2. Add the following script for your worker and update it as needed.
​

function rebuildUrl(incoming_url) {
// Tear apart the incoming URL
const url = new URL(incoming_url);
let { pathname, search, hash } = url;

// Remove the /blog/ part
if (pathname === "/blog") {
pathname = "/blog/";
}
pathname = pathname.replace(/^\/blog/,'');
return "https://MYCOMPANY.storychief.io" + pathname + search + hash;
}

async function handleRequest(request) {
const destinationURL = rebuildUrl(request.url);
request = new Request(request);

// Set the reverse proxy identifying header
request.headers.set("X-Referrer", "StoryChief");
return fetch(destinationURL, request);
}

addEventListener("fetch", async event => {
event.respondWith(handleRequest(event.request));
})

The script is rewriting every incoming URL from https://MYWEBSITE.com/blog/* to https://MYCOMPANY.storychief.io.
It also appends a header "X-Referrer": "StoryChief" to the request so StoryChief knows to handle it as a reversed proxy domain.

Step 3. Connect the worker

On the workers tab click "add route".
​

Step 4. Map the mywebsite.com/blog and mywebsite.com/blog/ route to the created worker.


πŸ“š Next steps

Did this answer your question?