Created
November 22, 2016 00:53
-
-
Save sleexyz/bc65f8e4cb9bbaaf569c75e95479f0b5 to your computer and use it in GitHub Desktop.
Build an application from middleware passed in variadically
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
const connectMiddleware = (...middleware) => (req, res) => { | |
const doAt = (i) => () => { | |
if (i === middleware.length) throw new Error ("MockError: out of middleware!"); | |
middleware[i](req, res, doAt(i+1)); | |
}; | |
doAt(0)(); | |
} | |
module.exports = connectMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment