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);
}
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);
}
5 Replies
Cyb3r-Jak3
Cyb3r-Jak315mo ago
Where are you seeing that? When you access the server or in the wrangler logs? That looks like you’re attempting to return some script but the headers are misconfigured so it is attempting to return as html
Nate G
Nate GOP15mo ago
In the console using inspect element When I go and get the callbacks from cloudflare, it all returns code 200 (ok) Everything appears to be in order
Cyb3r-Jak3
Cyb3r-Jak315mo ago
Are you using quick edit to develop the worker?
Nate G
Nate GOP15mo ago
Yes
Cyb3r-Jak3
Cyb3r-Jak315mo ago
My guess is that it is a quick dev bug and not an issue with your worker
Want results from more Discord servers?
Add your server