Skip to content

Instantly share code, notes, and snippets.

@tkers
Last active May 12, 2016 17:42
Show Gist options
  • Save tkers/8f5f009dc0a402a53a50f0151996865a to your computer and use it in GitHub Desktop.
Save tkers/8f5f009dc0a402a53a50f0151996865a to your computer and use it in GitHub Desktop.
// const composed = composeMiddleware(fn1, fn2, fn3);
const composeMiddleware = (head, ...tail) => (req, res, next) =>
head instanceof Function ?
head(req, res, () => composeMiddleware(...tail)(req, res, next)) :
next();
// var composed5 = composeMiddlewareES5([fn1, fn2, fn3]);
var composeMiddlewareES5 = funcs => (req, res, next) =>
funcs[0] instanceof Function ?
funcs[0](req, res, () => composeMiddlewareES5(funcs.slice(1))(req, res, next)) :
next();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment