What is the name of the domain?
What is the issue you’re encountering
DNS IP not changing when accessing from my home IP as set in the worker which should be modifying.
What steps have you taken to resolve the issue?
Hi all,
I’m looking to achieve the following setup using Cloudflare Workers for my domain lovesleep.co.uk:
Public users should continue to be routed to the existing production server (xx.xx.xx.132).
Only requests from my home IP (xx.xx.xx.62) should be routed to a new staging server (xx.xx.xx.30), while keeping the domain as lovesleep.co.uk.
I still want the DNS to resolve normally for everyone else — I just want Cloudflare to override the origin IP for my specific IP address.
New Production Server - Me
Old Production Server - All other internet users
I believe this can be done using a Worker and cf.resolveOverride, and here’s what I’ve drafted:
export default {
async fetch(request, env, ctx) {
const HOME_IP = 'xx.xx.xx.62';
const NEW_SERVER_IP = 'xx.xx.xx.30';
const clientIP = request.headers.get('cf-connecting-ip');
const url = new URL(request.url);
if (clientIP === HOME_IP) {
return fetch(url.toString(), {
cf: {
resolveOverride: NEW_SERVER_IP
},
headers: request.headers,
method: request.method,
body: request.body,
redirect: 'follow'
});
}
return fetch(request);
}
}
Am I approaching this the right way?
What feature, service or problem is this related to?
DNS records