Skip to content

Instantly share code, notes, and snippets.

@bpinedah
Created March 17, 2020 05:33
Show Gist options
  • Save bpinedah/3d52c4d0c9f93f0ba6db51562fc29e3b to your computer and use it in GitHub Desktop.
Save bpinedah/3d52c4d0c9f93f0ba6db51562fc29e3b to your computer and use it in GitHub Desktop.
Routes article
/**
* @description Create function with middlewares
* @param f Middleware functions to execute
* @returns {*}
* @private
*/
const _createPipeline = f => {
const signal = { continue: true };
return f.length > 1 ? f.reduce((before, after, idx) =>
e => before(e , _res(signal)(), _next(idx, f.length)).then(r => {
const response = signal.continue ? after(...[...r, _res(signal)(), _next(idx, f.length)]) : r;
signal.continue = true;
return response;
}
)) : e => f[0](e, _res(signal)(), _res(signal)().send).then(r => (r));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment