Using worker to serve content from different origin

Is it possible to detect the requesting IP, and then use that to control which origin server to send the request to?

The idea is we want to serve a different version of our website to internal users (for testing etc) but still use the same hostname as the public site.

Thanks

request.headers.get("cf-connecting-ip")

should get you the client IP address. Then you simply route the request to the right URL based on that address.

Thanks. So, I have this:

addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
if (request.headers.get(“cf-connecting-ip”) == ‘185.X.X.X’)
{
console.log(‘internal request change origin’);
}

const response = await fetch(request)
console.log(‘Got response’, response)
return response
}

How do I control the origin from there?

Thanks