Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Created December 7, 2016 20:00
Show Gist options
  • Save sleexyz/ce477b98c832c03fd76f100026f7b4b5 to your computer and use it in GitHub Desktop.
Save sleexyz/ce477b98c832c03fd76f100026f7b4b5 to your computer and use it in GitHub Desktop.
higher order middleware
const parseReqAndThen = (reqParser, onSuccess) => {
return (req, res, next) => {
const parseResult = reqParser(req);
if (typeof parseResult !== 'undefined') {
const successApp = connect()
.use(onSuccess(parseResult))
.use((req, res) => {next();});
successApp(req, res);
return;
}
next();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment