sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7k stars 434 forks source link

Defining middlewares in routes #1377

Open plashenkov opened 4 years ago

plashenkov commented 4 years ago

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:

export function get(req, res) {
  // ...
}

It would be nice to have an ability to define middlewares here as well.

thgh commented 4 years ago

Express has this in server.js: app.use('/admin', passport.authenticate). That will run this middleware only for admin routes.

ajbouh commented 4 years ago

I agree it would be valuable to keep middleware imports/declarations/usage close to the routes that depend on it.