Registry / web-framework / connect-injector

connect-injector

JSON →
library0.4.4jsnpmunverified

A middleware to inject content into any HTTP response, compatible with Connect and Express. Version 0.4.4 is the latest stable release (last updated in 2014). It allows conditional injection based on request/response headers and can modify response buffers on the fly. Key differentiator: intercept and transform responses before they are sent, unlike typical request-based middleware. Works with http-proxy for proxied content rewriting. Simple boolean condition function and a content converter function. No longer actively maintained; consider alternatives like express-transform or custom middleware.

npm install connect-injector
INSTALL
IMPORT
SIG · CONNECT-INJECTOR
C
connect-injector
web-frameworkjavascriptv0.4.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
var injector = require('connect-injector');
import injector from 'connect-injector'
Package is CommonJS only; does not support ESM natively. Use require().
injector function
var inject = injector(function(req, res) { return true; }, function(data, req, res, callback) { callback(null, data); });
var inject = injector({ when: function(req, res) { return true; }, convert: function(data, req, res, callback) {} });
The module exports a single function that takes two arguments: a condition function and a converter function. Do not pass an options object.
None (require only)
var injector = require('connect-injector');
No named exports. Use default require.

Demonstrates a basic connect-injector middleware that appends a paragraph to all HTML responses.

var connect = require('connect'); var injector = require('connect-injector'); var app = connect(); // Inject 'injected' into all text/html responses var inject = injector(function(req, res) { return res.getHeader('content-type') && res.getHeader('content-type').indexOf('text/html') === 0; }, function(data, req, res, callback) { var injectedContent = data.toString() + '<p>injected</p>'; callback(null, injectedContent); }); app.use(inject); app.use(function(req, res) { res.setHeader('content-type', 'text/html'); res.end('<html><body>Hello</body></html>'); }); app.listen(3000); console.log('Server running on port 3000');
Debug
Known issues
deprecatedPackage has not been updated since 2014. No longer maintained.
fix
Consider using alternatives like express-transform or write a custom middleware.
affects: >=0.0.0
gotchaThe injector must be placed before any middleware that writes the response, otherwise it won't intercept.
fix
Place injector middleware early in the stack, before any middleware that calls res.end() or res.write().
affects: >=0.0.0
gotchaIf the response has no content-type header, condition function may crash when accessing res.getHeader('content-type').
fix
Always check if the header exists before using its value: res.getHeader('content-type') && res.getHeader('content-type').indexOf(...).
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'indexOf' of undefined
The condition function tries to call indexOf on undefined content-type header.
fix
Check if res.getHeader('content-type') is defined before calling indexOf: return res.getHeader('content-type') && res.getHeader('content-type').indexOf('text/html') !== -1;
Error: connect-injector must be used before any middleware that writes to the response
The injector was placed after a middleware that already started writing or ended the response.
fix
Move injector middleware before any response-writing middleware.
Upgrade
Version history
0.4.4latest on npm
Audit
Dependencies
connectoptionalUsed as a middleware for Connect/Express, though not a hard dependency; requires the Connect-like API
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
connect-injector — npm install connect-injector · libregistry