Created
May 28, 2018 11:38
-
-
Save oakfang/d083e4ba8b3bab247313c8b22997b1c0 to your computer and use it in GitHub Desktop.
Compose middleware for express
This file contains 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
function composeMiddleware(...middleware) { | |
return (req, res, next) => middleware | |
.reverse() | |
.reduce( | |
(next, mw) => | |
() => mw(req, res, next), | |
next | |
)(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment