"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
Erisa4mo 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
ecc04mo ago
i assume this would work with non-GET requests like POSTs and PUTs, yeah? assuming it’s all in request
Erisa
Erisa4mo 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
ecc04mo ago
awesome
Want results from more Discord servers?
Add your server
More Posts
Sveltekit does not get the platform variable when processing api requestHello I have a Cloudflare Pages App using Sveltekit and I want to integrate R2. I have configured mDisable https for specific api routes?I have an API which a very old game is trying to send data to. This old application (circa 2004) canWrangler authentication storeCould someone please tell me where Wrangler stores authentication data on Windows? I setup a basic pUsing a custom domain from a different cloudflare accountHello there, a simple query: Is it possible to add a custom domain (apex) to my Pages app when the Neel help regarding cloud flareI got this mail from CloudFlare "one or more of your domain encountered an unexpected increase in bHyperdrive not working on local environmentHi, I'm getting an error from hyperdrive. ```js ✘ [ERROR] When developing locally, you should use aRequesting visibility on this community post: Documentation clarity around verified bots / WAF rulesHeyo, just requesting visibility on this post I made over @ the community forum >_> https://communiMomento Cache Integration UI 'An unknown error occurred'For some reason I'm not able to integrate Momento Cache with my Worker. When I press in the last butDurable Objects Transactional storage pricingQuoted from the docs `Requests that hit the Durable Objects in-memory cache or that use the multi-kNuxt and d1 context reference missingHi there, I have a thread in the general discussing that doesn't seemt to be getting much love https