Worker to copy one subdomain to another

This is my current worker that is supposed to get everything from stats.mydomain.com/status/server and push it to status.mydomain.com. However, I get this error: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

How do I fix this?


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

async function handleRequest(request) {
  const url = new URL(request.url);
  
  // Check if the incoming request is for status.gurzhiyfamily.com
  if (url.hostname === 'status.mydomain.com') {
    // Create a new request object to fetch content from stats.gurzhiyfamily.com/status/server
    const newRequest = new Request('https://stats.mydomain.com/status/server', {
      method: request.method,
      headers: request.headers,
      body: request.body
    });

    // Fetch the content and return as response
    const response = await fetch(newRequest);
    return new Response(response.body, {
      status: response.status,
      statusText: response.statusText,
      headers: response.headers
    });
  }
  
  // If not, proceed with the original request
  return fetch(request);
}
Was this page helpful?