"frame" forwarding with workers

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.
4 Replies
Erisa
Erisa9mo ago
export default {
async fetch(request) {
let url = new URL(request.url)
url.hostname = "othersite.example.com"
return fetch(url, request)
}
}
export default {
async fetch(request) {
let url = new URL(request.url)
url.hostname = "othersite.example.com"
return fetch(url, request)
}
}
ecc0
ecc0OP9mo ago
i assume this would work with non-GET requests like POSTs and PUTs, yeah? assuming it’s all in request
Erisa
Erisa9mo ago
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
ecc0
ecc0OP9mo ago
awesome
Want results from more Discord servers?
Add your server