Comment by bestest
1 month ago
Consider middleware.ts as a root middleware. Nothing is stopping you from creating your own chain (which is trivial) in there. I mean, that would eventually work the same if nextjs implemented that feature — there would be a root somewhere.
That doesn't answer parent's question.
People expect "middleware" to mean a certain thing and work a certain way.
express/koa give you the use() chain. next.js gives you one root, but nothing stops you from chaining yourself. same semantics, just manual wiring.
};
root is given, chain is trivial. that’s middleware.
Nothing trivial about that implementation in my mind - need to keep track of where middleware is registered, reduceRight is non obvious.
I expect these things to be standardized by the framework and all the sharp edges filed off - thats why I go to a framework in the first place.
1 reply →