Worker example using resolveOverride

Hello, am trying to get a simple worker setup which changes the upstream origin based on the country. The requirement however is to keep the Host header constant. My worker is as below, but am getting error code: 1006 from cloudflare. What am I missing? Also, would be super helpful if someone could share an example script that uses resolveOverride

const AU_TARGET_HOST = 'server1-ap-east.net';

const EU_TARGET_HOST = 'server1-eu.net';

async function handleRequest(request) {
    let config = {};
    const clientCountry = request.headers.get('CF-IPCountry')
    if(clientCountry === 'AU'){
        config.cf = {resolveOverride: AU_TARGET_HOST};
    }else{
      config.cf = {resolveOverride: EU_TARGET_HOST};
    }
    return fetch(request, config);

}

addEventListener('fetch', event => {
    event.passThroughOnException();
    event.respondWith(handleRequest(event.request));
});

See https://developers.cloudflare.com/workers/runtime-apis/request#requestinitcfproperties

However, resolveOverride will only take effect if both the URL host and the host specified by resolveOverride are within your zone. If either specifies a host from a different zone / domain, then the option will be ignored for security reasons.

My understanding is that your target hosts need to be subdomains of the same zone. Based on your example you’re specifying two different domains entirely, which while they might be in the same account, it doesn’t sound like that would work.

More discussion: Reverse Proxy (two different origin servers/CNAME's for the same domain) using Page Rules

Thanks @Judge , I did try using hosts from the same zone, but its still modifying the HOST and not retaining the value passed from the browser. Here is my modified code with dummy hostnames, but all from the same zone. Any suggestions on what I might be missing?

GET https://www.jsonanalyzer.online/?testingHost=123

const AU_TARGET_HOST = 'jsonanalyzer.online';

addEventListener('fetch', event => {
	event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
	const parsedUrl = new URL(request.url);
	const domain = parsedUrl.hostname;
	const path = parsedUrl.pathname;
  const query = parsedUrl.search;
  const clientCountry = request.headers.get('CF-IPCountry')
    if(clientCountry === 'AU'){
        config.cf = {resolveOverride: AU_TARGET_HOST};
    }
			return await fetch(`https://${AU_TARGET_HOST}${path}${query}`, {
				headers: request.headers,
				body: request.body,
				method: request.method,
			});
}