fixed backend errors, added delete and more configuration
This commit is contained in:
@@ -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' }
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user