-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Is there a lightweight way to compose middlewares? #502
Comments
not really anything specific no, you could just have your own called compress that takes N other middleware. For express you can just pass several and they get called in sequence but Connect doesn't have anything special
|
So there's no general builtin way to compose middleware, but Express router has such feature built in? |
Express just applies any number of middleware you want to a given route, validate things, blah blah |
You can always make your own conventions. Sometimes i do the following which keeps everything clean: // assume the following dir structure
/app
/app/routes
/app/routes/index.js
/app/routes/users.js
// index.js actually reads the files in `/app/routes` and builds a route index,
// maps the `exports.routes`, and then finally re-exports everything so you can do
// require('./routes') and get all of your routes elsewhere
// then every file in ./routes looks something like:
// users.js
exports.routes = {
// now this object basically maps to all of your resources using like so:
'/users': {
get: function () {},
post: function () {}
},
'/users/:id': {
get: function () {},
put: function () {}
}
} |
Sequenz library ( https://github.com/snd/sequenz/blob/master/lib/sequenz.coffee ) provides a helper:
What is the recommended way to compose middlewares this way? So whatever
handler
outputs gets compressed?The text was updated successfully, but these errors were encountered: