fixed file upload?

This commit is contained in:
2026-03-25 14:50:15 +01:00
parent 52e11a422c
commit 587954b164
2 changed files with 16 additions and 9 deletions

View File

@@ -8,6 +8,9 @@ import node from '@astrojs/node';
// https://astro.build/config
export default defineConfig({
output: 'server',
security: {
checkOrigin: false
},
image: {
service: { entrypoint: 'astro/assets/services/noop' }
},

View File

@@ -14,9 +14,7 @@ export const ALL: APIRoute = async ({ request, params }) => {
url.search = requestUrl.search;
const headers = new Headers();
// We must NOT forward 'host' (causes backend to reject if it doesn't match)
// We must NOT forward 'connection'
// We should let fetch recalculate 'content-length'
// Filter headers to avoid conflicts.
const forbiddenHeaders = ['host', 'connection', 'content-length', 'transfer-encoding', 'origin', 'referer'];
request.headers.forEach((value, key) => {
@@ -35,14 +33,20 @@ export const ALL: APIRoute = async ({ request, params }) => {
headers: headers,
};
// Only attach body for methods that allow it
// Safely handle body for mutating requests
if (request.method !== 'GET' && request.method !== 'HEAD') {
// Pass the raw stream directly. This is crucial for multipart/form-data.
fetchOptions.body = request.body;
// Clone the request to safely access the body stream
const reqClone = request.clone();
// For DELETE requests, check if a body actually exists before attaching it
// Some fetch implementations fail if a body is provided for DELETE
if (request.method !== 'DELETE' || reqClone.body) {
fetchOptions.body = reqClone.body;
// Required by Node.js fetch when body is a ReadableStream
// @ts-ignore
fetchOptions.duplex = 'half';
}
}
const response = await fetch(url.toString(), fetchOptions);