Open plashenkov opened 4 years ago
Express has this in server.js: app.use('/admin', passport.authenticate)
. That will run this middleware only for admin routes.
I agree it would be valuable to keep middleware imports/declarations/usage close to the routes that depend on it.
We can use middlewares in Express web-server (or other compatible) in
server.js
file. For example, session (e.g. express-session) or auth (e.g. passport.js) middlewares, etc. But some API endpoints or pages do not need these things at all. It seems now it's not possible to use specific middlewares on specific routes and not to use on others routes.Currently we can:
It would be nice to have an ability to define middlewares here as well.