Skip to content

Commit

Permalink
fix: move rewrite check to start of middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed May 22, 2024
1 parent a22138f commit 6ddf14f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/astro/src/actions/runtime/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export type Locals = {

export const onRequest = defineMiddleware(async (context, next) => {
const locals = context.locals as Locals;
// Actions middleware may have run already after a path rewrite.
// See https://github.com/withastro/roadmap/blob/feat/reroute/proposals/0047-rerouting.md#ctxrewrite
// `_actionsInternal` is the same for every page,
// so short circuit if already defined.
if (locals._actionsInternal) return ApiContextStorage.run(context, () => next());
if (context.request.method === 'GET') {
return nextWithLocalsStub(next, context);
}
Expand All @@ -23,12 +28,6 @@ export const onRequest = defineMiddleware(async (context, next) => {
return nextWithStaticStub(next, context);
}

// Actions middleware may have run already after a path rewrite.
// See https://github.com/withastro/roadmap/blob/feat/reroute/proposals/0047-rerouting.md#ctxrewrite
// `_actionsInternal` is the same for every page,
// so short circuit if already defined.
if (locals._actionsInternal) return ApiContextStorage.run(context, () => next());

const { request, url } = context;
const contentType = request.headers.get('Content-Type');

Expand Down

0 comments on commit 6ddf14f

Please sign in to comment.