0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

fix: remove FormData fallback from route

This commit is contained in:
bholmesdev 2024-04-23 19:04:13 -04:00
parent 171aad839c
commit e8d8a780da

View file

@ -10,13 +10,14 @@ export const POST: APIRoute = async (context) => {
const actionPathKeys = url.pathname.replace('/_actions/', '').split('.');
const action = await getAction(actionPathKeys);
const contentType = request.headers.get('Content-Type');
let args: any;
if (contentType === 'application/json') {
args = await request.clone().json();
}
if (formContentTypes.some((f) => contentType?.startsWith(f))) {
args = await request.clone().formData();
if (contentType !== 'application/json') {
throw new ActionError({
status: 'INTERNAL_SERVER_ERROR',
message:
'Called an action with a non-JSON body. To enhance an action to accept form data, add `enhance: true` to your `defineAction()` config.',
});
}
const args = await request.clone().json();
let result: unknown;
try {
result = await ApiContextStorage.run(context, () => action(args));