fix proxy + file upload

This commit is contained in:
grngxd 2025-06-08 10:05:05 +01:00
parent db68058d5b
commit 5453d49c92
4 changed files with 92 additions and 9 deletions

View file

@ -4,20 +4,24 @@ const proxy = async ({ send, url, pathname, request }: RequestEvent) => {
const targetUrl = new URL(`http://localhost:8081${pathname}`, url);
const headers = new Headers(request.headers);
const backendResponse = await fetch(targetUrl, {
const fetchOptions: RequestInit = {
method: request.method,
headers,
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body : undefined,
redirect: 'manual',
});
};
console.log(`Proxying ${request.method} request to: ${targetUrl.href}`);
if (request.method !== 'GET' && request.method !== 'HEAD') {
fetchOptions.body = request.body;
(fetchOptions as any).duplex = 'half';
}
const res = await fetch(targetUrl, fetchOptions);
send(
new Response(backendResponse.body, {
status: backendResponse.status,
statusText: backendResponse.statusText,
headers: backendResponse.headers,
new Response(res.body, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
})
);
};