Skip to content

Instantly share code, notes, and snippets.

@doroved
Last active June 3, 2026 14:19
Show Gist options
  • Select an option

  • Save doroved/f3370bc1e4fb0f8bc4e54cf2e2b00bd0 to your computer and use it in GitHub Desktop.

Select an option

Save doroved/f3370bc1e4fb0f8bc4e54cf2e2b00bd0 to your computer and use it in GitHub Desktop.
Proxying ntc.party through CF workers
export default {
async fetch(request) {
const url = new URL(request.url);
const workerHost = url.host;
const targetHost = 'ntc.party';
if (url.pathname === '/robots.txt') {
return new Response('User-agent: *\nDisallow: /', {
headers: { 'Content-Type': 'text/plain' }
});
}
url.hostname = targetHost;
url.protocol = 'https:';
const newHeaders = new Headers(request.headers);
newHeaders.set('Host', targetHost);
newHeaders.set('Origin', `https://${targetHost}`);
newHeaders.set('Referer', `https://${targetHost}/`);
const newRequest = new Request(url, {
method: request.method,
headers: newHeaders,
body: request.body,
redirect: 'manual'
});
const response = await fetch(newRequest);
const newResponseHeaders = new Headers(response.headers);
newResponseHeaders.set('X-Robots-Tag', 'noindex, nofollow, noarchive');
const contentType = newResponseHeaders.get('content-type');
if (contentType && (contentType.includes('text/html') || contentType.includes('text/css') || contentType.includes('application/json') || contentType.includes('javascript'))) {
let bodyText = await response.text();
const from = `https://${targetHost}`;
const to = `https://${workerHost}`;
bodyText = bodyText.replaceAll(`="${from}`, `="${to}`);
bodyText = bodyText.replaceAll(`='${from}`, `='${to}`);
bodyText = bodyText.replaceAll(`("${from}`, `("${to}`);
bodyText = bodyText.replaceAll(`('${from}`, `('${to}`);
bodyText = bodyText.replaceAll(`=\\"${from}`, `=\\"${to}`);
bodyText = bodyText.replaceAll(`"${from}`, `"${to}`);
bodyText = bodyText.replaceAll(`u003e${from}`, `u003e${to}`);
return new Response(bodyText, {
status: response.status,
statusText: response.statusText,
headers: newResponseHeaders
});
}
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newResponseHeaders
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment