I have a worker setup to Proxy to another web service provider.
I need to make sure I’m sending:
“X-Proxy-Origin”,“mainsite.com”)
Here is my worker that redirects properly, but doesn’t send the header option.
const DOMAIN = ‘maindomain.com’; //
const PROXYPATH = ‘locations’; // path to be proxied
const ORIGIN = ‘locations.seocompany.com.company’; // where to fetch content from
addEventListener(‘fetch’, event => {
var url = new URL(event.request.url);
if (url.pathname.startsWith(‘/’ + PROXYPATH + ‘/’) || url.pathname === ‘/’ + PROXYPATH) {
handleRequest(event, url);
} else {
event.respondWith(fetch(event.request));
}
})
async function handleRequest(event, url) {
// Change URL from public URL to use the origin URL
var originUrl = url.toString().replace(
‘https://’ + DOMAIN + ‘/’ + PROXYPATH,
‘https://’ + ORIGIN
);
event.passThroughOnException();
event.respondWith(fetch(originUrl));
}
Any guidance on how I could so this?