Created
May 3, 2019 15:52
-
-
Save laat/0a36c4b2c1ebb0c0bb39f2c2393c1e76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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