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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user