Skip to content

Instantly share code, notes, and snippets.

@laat
Created May 3, 2019 15:52
Show Gist options
  • Save laat/0a36c4b2c1ebb0c0bb39f2c2393c1e76 to your computer and use it in GitHub Desktop.
Save laat/0a36c4b2c1ebb0c0bb39f2c2393c1e76 to your computer and use it in GitHub Desktop.
import { RequestHandler } from 'express';
/**
* Combine multiple middleware together.
* @param mids
*/
export const combineHandlers = (...mids: RequestHandler[]): RequestHandler =>
mids.reduce((a, b) => (req, res, next) => {
a(req, res, err => {
if (err) {
return next(err);
}
b(req, res, next);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment