Cloudflare Worker Proxy addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); }); const TARGET_URL = "[https://hostloc.com](https://hostloc.com/)"; const TARGET_URL_REGEXP = /hostloc\.com/g; const TARGET_HOSTNAME = new URL(TARGET_URL).hostname; const handleRequest = async request => { const url = new URL(request.url); url.hostname = TARGET_HOSTNAME; let headers = new Headers(request.headers); headers.set("Referer", TARGET_URL); headers.set("User-Agent", request.headers.get("user-agent")); const param = { method: request.method, headers: headers, body: request.body, redirect: "manual" } const response = await fetch(url, param); return handleResponse(request, response); } const handleResponse = async (request, response) => { const contentType = response.headers.get('content-type'); let headers = new Headers(response.headers); headers.set('Access-Control-Allow-Origin', '*'); headers.set('Access-Control-Allow-Methods', 'GET'); headers.set('Access-Control-Allow-Headers', 'Content-Type'); let location = response.headers.get('location'); if (location) { location = location.replace(TARGET_URL_REGEXP, new URL(request.url).hostname); headers.set('location', location); } const data = (contentType && contentType.includes('text')) ? await response.text() : await response.blob(); const modifiedData = (typeof data === 'string') ? data.replace(TARGET_URL_REGEXP, new URL(request.url).hostname) : data; return new Response(modifiedData, { status: response.status, statusText: response.statusText, headers: headers }); }