URL rewrite with workers

Hi,

Can I get some help with creting a worker for transparent URL rewrites? My goal is to rewrite from https://www.mysite.com/info to https://info.mysite.com.
I am working with this sample code:

const HOSTNAMES = [‘www.mysite.com’]
async function handleRequest(request) {

let url = new URL(request.url)

if (HOSTNAMES.includes(url.hostname)) {

return <the new URL>

}
return fetch(request)
}
addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})

The function should return a new URL, but I can’t figure out which class to use. I think “Response.url” but It gives me some error which are out of my scope.

Any help would be appreciated.