Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Multiple middleware #74700

Open
jake-normal opened this issue Jan 9, 2025 · 0 comments
Open

Docs: Multiple middleware #74700

jake-normal opened this issue Jan 9, 2025 · 0 comments
Labels
Documentation Related to Next.js' official documentation.

Comments

@jake-normal
Copy link

What is the documentation issue?

https://nextjs.org/docs/app/building-your-application/routing/middleware#convention

Is there any context that might help us understand?

The documentation contains the following statement:

Note: While only one middleware.ts file is supported per project, you can still organize your middleware logic modularly. Break out middleware functionalities into separate .ts or .js files and import them into your main middleware.ts file. This allows for cleaner management of route-specific middleware, aggregated in the middleware.ts for centralized control. By enforcing a single middleware file, it simplifies configuration, prevents potential conflicts, and optimizes performance by avoiding multiple middleware layers.

The docs seem to imply that the mere act of importing multiple files exporting a middleware and config object is enough to use multiple middleware. But I imagine there is actually a composition step missing. Obviously middleware can be composed with function composition, but what isn't clear is how to combine multiple config objects and matchers, that is, to ensure that each middleware is associated with a given matcher.

Can we get an example of importing more than one middleware, each with its own matcher config?

Does the docs page already exist? Please link to it.

No response

@jake-normal jake-normal added the Documentation Related to Next.js' official documentation. label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Related to Next.js' official documentation.
Projects
None yet
Development

No branches or pull requests

1 participant