From f4e2b8cf754b460d908801a5a18f2cf18ea0d1eb Mon Sep 17 00:00:00 2001 From: giancarlo Date: Sun, 12 May 2024 14:52:12 +0700 Subject: [PATCH] Add action path to request headers for server actions In the middleware.ts file, an action path has been appended to the request headers. This is particularly useful for identifying the action path in server actions. If the action is recognized as a server action, the 'x-action-path' is then set with the respective pathname from the request. --- apps/web/middleware.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts index e75cb6ecf..da446eecf 100644 --- a/apps/web/middleware.ts +++ b/apps/web/middleware.ts @@ -45,6 +45,12 @@ export async function middleware(request: NextRequest) { } } + // append the action path to the request headers + // which is useful for knowing the action path in server actions + if (isServerAction(request)) { + csrfResponse.headers.set('x-action-path', request.nextUrl.pathname); + } + // if no pattern handler returned a response, // return the session response return csrfResponse;