Skip to content

Instantly share code, notes, and snippets.

Pipeline

This is a simple functional pipeline implementation that allows the user to execute middleware through a series of sequential steps. It also exposes a compose function for chaining together higher order components.

Pipeline/Middleware Usage

import pipeline, { Middleware } from "./pipeline";

const firstStep: Middlware<any, any> = async (payload, next) => {
 console.log(payload);
@Curtis017
Curtis017 / index.ts
Created March 8, 2019 03:29
Simple middleware implementation using typescript and ES6
import pipeline, { Middleware } from './pipeline';
const step1: Middleware<any, any> = (req, res, next) => {
if (req.body) {
console.log(`STEP 1: \n req: ${JSON.stringify(req)}\n res: ${JSON.stringify(res)}`);
next();
}
}
const step2: Middleware<any, any> = async (req, res, next) => {