tamper
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

tamper

Node.js middleware to capture and modify response bodies

Build Status

Installation

npm install tamper

Usage

var tamper = require('tamper');
 
app.use(tamper(function(req, res) {
 
  // Look at the request or the response headers and decide what to do.
 
  // In this case we only want to modify html responses:
  if (res.getHeader('Content-Type') != 'text/html') {
 
    // When returning a falsy value processing will continue as usual
    // without any performance impact.
    return;
  }
 
  // Return a function in order to capture and modify the response body:
  return function(body) {
    // The function may either return a Promise or a string
    return body.replace(/foo/g, 'bar');
  };
 
});

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    928
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    928
  • 1.0.0
    38
  • 0.1.0
    1,498

Package Sidebar

Install

npm i tamper

Weekly Downloads

2,464

Version

1.1.0

License

none

Unpacked Size

9.55 kB

Total Files

8

Last publish

Collaborators

  • fgnass