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.
This commit is contained in:
giancarlo
2024-05-12 14:52:12 +07:00
parent 7ada6b53c6
commit f4e2b8cf75

View File

@@ -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;