Cloudflare Worker Setup
Host EarlySEO "Free Tools" on a subfolder of your main domain using Cloudflare Workers.
Goal
Serve tools under a subpath like:
https://example.com/tools/*
while the actual tool app might live on a different origin.
High-level steps
- Create a Worker in Cloudflare Workers dashboard
- Add a route like
example.com/tools/* - In the Worker, proxy requests to the tools origin
- Set caching/headers as needed
- Test end-to-end (including assets, API calls, and client-side routing)
Example Worker (proxy)
Replace TOOLS_ORIGIN with the upstream host that serves your tool app.
export default {
async fetch(request) {
const url = new URL(request.url);
// strip "/tools" prefix
url.pathname = url.pathname.replace(/^\/tools/, '') || '/';
const upstream = new URL(`https://TOOLS_ORIGIN${url.pathname}${url.search}`);
const resp = await fetch(upstream.toString(), request);
// You may want to add caching headers here
return resp;
},
};Gotchas
- If the upstream app uses absolute URLs, you may need to rewrite them.
- If you have API calls under
/api, ensure those are also routed correctly. - For SPAs, you may need to fallback to
index.htmlfor unknown paths.