Middleware
intercepts request
or response
before they are passed to application's core code.
Then, based on the incoming request
, you can modify the response
by rewriting, redirecting, modifying the request or response headers, or responding directly
cached content
and routes
are matchedYou can set CORS headers
in Middleware
to allow cross-origin requests
Use the file middleware.ts
in the root of your project to define Middleware
pages
or app
, or inside src
if applicablematcher
matcher
allows you to filter Middleware
to run on specific paths
export const config = { matcher: [ '/about/:path*', '/dashboard/:path*' ], }