mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix(actions): pass actionAPIContext to action handler instead of APIContext (#12301)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
parent
ecc4402b3a
commit
0cfc69d499
3 changed files with 9 additions and 2 deletions
5
.changeset/shy-eggs-grin.md
Normal file
5
.changeset/shy-eggs-grin.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes an issue with action handler context by passing the correct context (`ActionAPIContext`).
|
|
@ -99,7 +99,8 @@ async function handlePost({
|
||||||
if (contentType && hasContentType(contentType, formContentTypes)) {
|
if (contentType && hasContentType(contentType, formContentTypes)) {
|
||||||
formData = await request.clone().formData();
|
formData = await request.clone().formData();
|
||||||
}
|
}
|
||||||
const action = baseAction.bind(context);
|
const { getActionResult, callAction, props, redirect, ...actionAPIContext } = context;
|
||||||
|
const action = baseAction.bind(actionAPIContext);
|
||||||
const actionResult = await action(formData);
|
const actionResult = await action(formData);
|
||||||
|
|
||||||
if (context.url.searchParams.get(ACTION_QUERY_PARAMS.actionRedirect) === 'false') {
|
if (context.url.searchParams.get(ACTION_QUERY_PARAMS.actionRedirect) === 'false') {
|
||||||
|
|
|
@ -27,7 +27,8 @@ export const POST: APIRoute = async (context) => {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
|
||||||
return new Response(null, { status: 415 });
|
return new Response(null, { status: 415 });
|
||||||
}
|
}
|
||||||
const action = baseAction.bind(context);
|
const { getActionResult, callAction, props, redirect, ...actionAPIContext } = context;
|
||||||
|
const action = baseAction.bind(actionAPIContext);
|
||||||
const result = await action(args);
|
const result = await action(args);
|
||||||
const serialized = serializeActionResult(result);
|
const serialized = serializeActionResult(result);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue