←back to thread

Next.js is infuriating

(blog.meca.sh)
1033 points Bogdanp | 4 comments | | HN request time: 0s | source
Show context
pavel_lishin ◴[] No.45102328[source]
> Let's not skip over the fact that you can't have multiple middlewares or chain them either.

Surely this can't be right?

https://nextjs.org/docs/messages/nested-middleware > If you have more than one Middleware, you should combine them into a single file and model their execution depending on the incoming request.

By Talos, this can't be happening.

replies(2): >>45102832 #>>45105164 #
1. zelphirkalt ◴[] No.45102832[source]
Am I reading this correctly? They are advocating giving up on structuring code in separate files? Is that a scoping problem that NextJS has, which makes it difficult to use multiple files? Seems like a rather ridiculous statement of a framework to make.
replies(1): >>45103701 #
2. wetoastfood ◴[] No.45103701[source]
It's the single file that is used to define the middleware function that runs. You can import whatever you want into it and decide how "you should combine [your middleware] into a single file."
replies(2): >>45103778 #>>45105074 #
3. hn_acc_2 ◴[] No.45103778[source]
I prefer this to having app.use / router.use scattered anywhere throughout the app init (i.e. Express)
4. qbane ◴[] No.45105074[source]
As a JavaScript developer, combining/consolidating middlewares manually just defeats the design of middleware. I would rather call it a callback function.