middleware
Middleware refers to functions that intercept and process incoming requests before they reach their final route handlers.
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 matched.For example - You 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*' ], }