Connect (Node.js)
Connectr forConnectr is a layer on top of Connect that allows the insertion/removal of middlewares after the stack has been built. This is especially useful when you don't have access to the code that sets up your Connect stack (a third party module for example).
This module also supports Express.
Install
npm install connectr
Usage
var connectr = app; // you can also monkey patch app directly:// app = require('connectr').patch(app) // Add labeled middlewareconnectr; // Label middleware which is at a specific position on the stack// This should be used only if you don't have access to the code// that builds the stack.//// Tip: use `app.stack` to inspect the stackconnectrindexindex; // Insert before middlewareconnectr; // Insert after middlewareconnectr; // Insert at beginning of stackconnectr; // Remove middlewareconnectr; // Assign a label to middleware already in the stackconnectrindexi; // the .as, .before and .after calls are optional // have a problem? try console.log(app.stack)
Simple Example
var connect = var app = ;var connectr = app; connectr; /* ... */ connectr;
Kitchen Sink Example
var http = connect = app = connectr = app; var cookieParser = connect; // we need to manually label middlewarescookieParserlabel = 'cookieParser'; app; connectr; connectr; // you can also use connectr to label your middlewares// instead of labeling them manually as above connectr; connectr; connectr; connectr; connectr; //console.log(app.stack); http;