From 6ddf14f7c242be38f0f32d408c15ef2e49fd78e8 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 22 May 2024 12:12:20 -0400 Subject: [PATCH] fix: move rewrite check to start of middleware --- packages/astro/src/actions/runtime/middleware.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/astro/src/actions/runtime/middleware.ts b/packages/astro/src/actions/runtime/middleware.ts index c78ac317c7f4f..86a9dc5d637f6 100644 --- a/packages/astro/src/actions/runtime/middleware.ts +++ b/packages/astro/src/actions/runtime/middleware.ts @@ -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); } @@ -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');