Proxy subfolder to subdomain with worker


I am trying to setup a worker script that will redirect my subfolder request to a subdomain, for example to

The code that I have is this:

let url = new URL(request.url);
url.hostname = url.hostname.replace(/www./, ‘test.’)
return fetch(url)

The problem is that all of the css and js scripts are then trying to load from instead of because they are relative links.

How would I handle this without creating a /test/ folder on my subdomain?