Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Created November 22, 2016 00:53
Show Gist options
  • Save sleexyz/bc65f8e4cb9bbaaf569c75e95479f0b5 to your computer and use it in GitHub Desktop.
Save sleexyz/bc65f8e4cb9bbaaf569c75e95479f0b5 to your computer and use it in GitHub Desktop.
Build an application from middleware passed in variadically
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