Skip to content

Instantly share code, notes, and snippets.

@lcanady
Last active December 7, 2020 20:55
Show Gist options
  • Select an option

  • Save lcanady/8b0d7774f52d5ed024a38038c74bbbc2 to your computer and use it in GitHub Desktop.

Select an option

Save lcanady/8b0d7774f52d5ed024a38038c74bbbc2 to your computer and use it in GitHub Desktop.
A Middleware engine written in typescript
/**
* Declare a new middleware pipeline.
* @param middlewares A list of middlewares to add to the pipeline on
* instantiation.
*/
export function pipeline<T>(...middlewares: Middleware<T>[]): Pipe<T> {
const stack: Middleware<T>[] = middlewares;
/**
* Add middlewares to the pipeline.
* @param middlewares A list of middlewares to add to the current
* pipeline.
*/
const use: Pipe<T>["use"] = (...middlewares) => {
stack.push(...middlewares);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment