i would like to know how to have a worker passthrough requests from my domain to another domain running a service, but keeping the domain shown in the url bar as my domain. i've looked on the forum seeing many posts saying workers can do it, but none detailing how. if possible, i'd like to avoid iframes and have the worker basically copy the full request and send it upstream.
#"frame" forwarding with workers
6 messages · Page 1 of 1 (latest)
export default {
async fetch(request) {
let url = new URL(request.url)
url.hostname = "othersite.example.com"
return fetch(url, request)
}
}```
i assume this would work with non-GET requests like POSTs and PUTs, yeah?
assuming it’s all in request
Yes - the only thing changing is the hostname, everything else stays the same
the , request part of the fetch is vital for that, as you rightly noticed