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-injectorVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic connect-injector middleware that appends a paragraph to all HTML responses.
Consider using alternatives like express-transform or write a custom middleware.
Place injector middleware early in the stack, before any middleware that calls res.end() or res.write().
Always check if the header exists before using its value: res.getHeader('content-type') && res.getHeader('content-type').indexOf(...).Check if res.getHeader('content-type') is defined before calling indexOf: return res.getHeader('content-type') && res.getHeader('content-type').indexOf('text/html') !== -1;Move injector middleware before any response-writing middleware.