Skip to content

fgnass/tamper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Node.js middleware to capture and modify response bodies

Resources

License

Stars

Watchers

Forks

Packages

No packages published