updated ui and file creation

This commit is contained in:
2026-03-25 14:09:15 +01:00
parent e53cdfef03
commit fe2489b4ed
5 changed files with 20 additions and 12 deletions
+14 -6
View File
@@ -8,13 +8,14 @@ export const ALL: APIRoute = async ({ request, params }) => {
return new Response(JSON.stringify({ error: 'Missing path' }), { status: 400 });
}
// Ensure path is properly encoded
const url = new URL(`${API_URL}/api/${path}`);
const requestUrl = new URL(request.url);
url.search = requestUrl.search;
// Filter headers to avoid conflicts with the backend container
const headers = new Headers();
const forbiddenHeaders = ['host', 'connection', 'origin', 'referer', 'content-length'];
// Filter headers to avoid conflicts. Content-Type is handled automatically for POST/PUT if we pass arrayBuffer.
const forbiddenHeaders = ['host', 'connection', 'origin', 'referer', 'content-length', 'transfer-encoding'];
request.headers.forEach((value, key) => {
if (!forbiddenHeaders.includes(key.toLowerCase())) {
@@ -23,16 +24,23 @@ export const ALL: APIRoute = async ({ request, params }) => {
});
try {
console.log(`[Proxy] ${request.method} ${requestUrl.pathname} -> ${url.toString()}`);
let body: any = undefined;
if (request.method !== 'GET' && request.method !== 'HEAD') {
body = await request.arrayBuffer();
}
const response = await fetch(url.toString(), {
method: request.method,
headers: headers,
// Pass the body stream directly for efficiency
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body : undefined,
// @ts-ignore - duplex is required for streaming bodies in some fetch implementations
body: body,
// @ts-ignore
duplex: 'half'
});
// Extract headers for the response
console.log(`[Proxy] Backend returned ${response.status} for ${url.toString()}`);
const responseHeaders = new Headers();
response.headers.forEach((value, key) => {
responseHeaders.set(key, value);