fixed file upload?
This commit is contained in:
@@ -8,6 +8,9 @@ import node from '@astrojs/node';
|
|||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
output: 'server',
|
output: 'server',
|
||||||
|
security: {
|
||||||
|
checkOrigin: false
|
||||||
|
},
|
||||||
image: {
|
image: {
|
||||||
service: { entrypoint: 'astro/assets/services/noop' }
|
service: { entrypoint: 'astro/assets/services/noop' }
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ export const ALL: APIRoute = async ({ request, params }) => {
|
|||||||
url.search = requestUrl.search;
|
url.search = requestUrl.search;
|
||||||
|
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
// We must NOT forward 'host' (causes backend to reject if it doesn't match)
|
// Filter headers to avoid conflicts.
|
||||||
// We must NOT forward 'connection'
|
|
||||||
// We should let fetch recalculate 'content-length'
|
|
||||||
const forbiddenHeaders = ['host', 'connection', 'content-length', 'transfer-encoding', 'origin', 'referer'];
|
const forbiddenHeaders = ['host', 'connection', 'content-length', 'transfer-encoding', 'origin', 'referer'];
|
||||||
|
|
||||||
request.headers.forEach((value, key) => {
|
request.headers.forEach((value, key) => {
|
||||||
@@ -35,14 +33,20 @@ export const ALL: APIRoute = async ({ request, params }) => {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only attach body for methods that allow it
|
// Safely handle body for mutating requests
|
||||||
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
||||||
// Pass the raw stream directly. This is crucial for multipart/form-data.
|
// Clone the request to safely access the body stream
|
||||||
fetchOptions.body = request.body;
|
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
|
// Required by Node.js fetch when body is a ReadableStream
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fetchOptions.duplex = 'half';
|
fetchOptions.duplex = 'half';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url.toString(), fetchOptions);
|
const response = await fetch(url.toString(), fetchOptions);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user