Worker reverse proxy script not

Worker reverse proxy script not routing or preserving the html host headers and dir path from the end user. Example: Reverse proxy must forward host header as but it is coming in as

routes have been added to the domain as*

My worker script below:

addEventListener(‘fetch’, event => {

async function handleRequest(request) {
// Extract the ‘Host’ header from the original request
const hostHeader = request.headers.get(‘Host’);

if (!hostHeader) {
return new Response(‘Host header not found in the request.’, { status: 400 });

// Define the URL of your reverse proxy
const proxyURL = '';

// Modify the request’s URL to point to the reverse proxy
const url = new URL(request.url); = new URL(proxyURL).host;
url.protocol = new URL(proxyURL).protocol;

// Forward the modified request to the reverse proxy while preserving the ‘Host’ header
const response = await fetch(url, {
method: request.method,
headers: request.headers,
body: request.body

return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers