Usama Shabbir
Usama Shabbir
CDCloudflare Developers
Created by Usama Shabbir on 2/17/2025 in #workers-help
Hi,
I'm using Cloudflare Workers to navigate between different applications without changing the host name. However, due to several reasons, I'm not sure if this technique will work as expected unless I add custom domains. The moment I add the custom domain, it changes my base host URL to the one I'm navigating to. Here's why I’m doing this: My website is hosted on Cloudflare Pages, and the other two applications are dynamic apps deployed on separate VMs. Previously, I was handling this with NGINX, but now I want to use Cloudflare Pages for my static site to improve its performance. Unfortunately, I'm stuck with this issue. Below is my worker implementation:
export default {
async fetch(request) {
let url = new URL(request.url);

if (url.pathname.startsWith("/tools")) {
return fetch(`https://tools.cf.worker.whoisfreaks.com${url.pathname}`, request);
}

if (url.pathname.includes("/resources")) {
return fetch(`https://blogs.cf.worker.whoisfreaks.com${url.pathname}`, request);
}

if (url.pathname.includes("/blog")) {
return fetch(`https://blogs.cf.worker.whoisfreaks.com${url.pathname}`, request);
}

if (url.pathname.includes("/_next")) {
return fetch(`https://blogs.cf.worker.whoisfreaks.com${url.pathname}${url.search ? '?' + url.searchParams.toString() : ''}`, request);
}

return fetch(`https://wf-website-1if.pages.dev${url.pathname}`, request);
}
};
export default {
async fetch(request) {
let url = new URL(request.url);

if (url.pathname.startsWith("/tools")) {
return fetch(`https://tools.cf.worker.whoisfreaks.com${url.pathname}`, request);
}

if (url.pathname.includes("/resources")) {
return fetch(`https://blogs.cf.worker.whoisfreaks.com${url.pathname}`, request);
}

if (url.pathname.includes("/blog")) {
return fetch(`https://blogs.cf.worker.whoisfreaks.com${url.pathname}`, request);
}

if (url.pathname.includes("/_next")) {
return fetch(`https://blogs.cf.worker.whoisfreaks.com${url.pathname}${url.search ? '?' + url.searchParams.toString() : ''}`, request);
}

return fetch(`https://wf-website-1if.pages.dev${url.pathname}`, request);
}
};
If anyone has any insights or ideas on how to resolve this, that would be greatly appreciated!
1 replies