Hi,
I have a website at https://smug-chicken.pages.dev
, hosted on pages. I have another website at https://blog-smug.pages.dev
. I want it so when I go to https://smug-chicken.pages.dev/about
, it loads up the https://blog-smug.pages.dev
. (Ignore the blog part, it was just a name I gave to the website to test).
From what I have read online, it should be quite simple with Cloudflare Workers. I am hosting both websites on Cloudflare Pages, obviously with different names.
I have create a new Worker. Create Service → HTTP handler and pasted the following code:
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.pathname.startsWith('/about')) {
const blogUrl = 'https://myaboutpage.com;
const modifiedRequest = new Request(blogUrl, request);
return fetch(modifiedRequest);
} else {
return fetch(request);
}
}
}
I saved and deployed that code. I then went back to the worker, went to Triggers, and added a route. The route I added was https://smug-chicken.pages.dev/about*
. I also tried https://smug-chicken.pages.dev/about
and https://smug-chicken.pages.dev/*
.
Back in where you edit your code, In the little IDE, I type in https://smug-chicken.pages.dev/about
and it returns the code from https://blog-smug.pages.dev
. When I run it in the browser, it just goes the 404 page on https://smug-chicken.pages.dev
.
Where am I going wrong here??
Also, when I go to the worker, directly from the worker URL https://{my-worker-name}.workers.dev/about
, its trying to bring down the CSS, JS from https://{my-worker-name}/main.js
etc.