fixed backend errors, added delete and more configuration

This commit is contained in:
2026-03-25 13:20:04 +01:00
parent d47f30a53a
commit 3ec009c86d
7 changed files with 606 additions and 154 deletions
+33
View File
@@ -0,0 +1,33 @@
import type { APIRoute } from 'astro';
export const ALL: APIRoute = async ({ request, params }) => {
const API_URL = process.env.PUBLIC_API_URL || 'http://backend:3000';
const path = params.path;
const url = new URL(`${API_URL}/api/${path}`);
// Forward search parameters
const requestUrl = new URL(request.url);
url.search = requestUrl.search;
try {
const response = await fetch(url.toString(), {
method: request.method,
headers: request.headers,
body: request.method !== 'GET' && request.method !== 'HEAD' ? await request.arrayBuffer() : undefined,
// @ts-ignore
duplex: 'half'
});
return new Response(response.body, {
status: response.status,
headers: response.headers
});
} catch (e) {
console.error(`Proxy error for ${url}:`, e);
return new Response(JSON.stringify({ error: 'Proxy error' }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
};