Skip to content

giddyinc/middleware-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

feee6dd · Dec 7, 2022

History

44 Commits
Jun 3, 2020
Jun 3, 2020
Jun 3, 2020
Jun 5, 2018
Jun 3, 2020
Jun 5, 2018
Jun 3, 2020
Jun 5, 2018
Jun 3, 2020
Aug 10, 2017
Sep 14, 2017
Dec 7, 2022
Dec 7, 2022
Dec 7, 2022
Jun 5, 2018

Repository files navigation

NPM version Build Status Coverage Status

middleware-container

$ npm install --save middleware-container

Overview

Middleware container extends the boxed-injector functionality for use with express middleware. The use case for this is when middleware chains get complex.

The problem that this package solves is:

  • Simplifying declarativeness of common middleware packages (multiple middlewares used often around your app - why declare multiple times?)
  • Middleware dependency chains (avoid having to declare multiple middleware functions on multiple routes, and having to maintain them in the correct order // with all sub-middlewares)
  • Middleware redundancy (sometimes middlewares have dependencies that may get executed multiple times if not composed)

Usage

middleware-container is built on top of boxed-injector

const MiddlewareContainer = require('middleware-container');
const middlewares = new MiddlewareContainer();

middlewares.register('getOneThing', (req, res, next) => next());

middlewares.register('getAnotherThingThatDependsOnOneThing', (req, res, next) => next(), {
  depends: 'getOneThing'
});

middlewares.register('getSomethingThatDependsOnThePrevious', (req, res, next) => next(), {
  depends: 'getAnotherThingThatDependsOnOneThing'
});

// /foo will have the entire middleware chain executed
app.get('/foo', middlewares.get('getSomethingThatDependsOnThePrevious'), (req, res) => res.send(res.locals));
    

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published