feat: enhance response handling for fetch requests

Improve reliability by ensuring fetch responses are properly wrapped in a new Response object, preserving headers and status codes.
This commit is contained in:
ccbikai
2024-09-06 18:35:39 +08:00
parent faa2c567ac
commit f36f07cf35

View File

@@ -16,7 +16,8 @@ export async function GET({ request, params, url }) {
if (!targetWhitelist.some(domain => target.hostname.endsWith(domain))) {
return Response.redirect(target.toString(), 302)
}
return fetch(target.toString(), request)
const response = await fetch(target.toString(), request)
return new Response(response.body, response)
}
catch (error) {
return new Response(error.message, { status: 500 })