JSPM

response-distort

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q21429F
  • License MIT

Hooks into an http.ServerResponse instance to modify its response body

Package Exports

  • response-distort

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (response-distort) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

response-distort

Hooks into an http.ServerResponse instance to modify its response body.

Useful, for example, to inject JavaScript into an HTML response.

Usage

NPM

distort(res, map(body, done))

Accepts res, an instance of http.ServerResponse, and map, a callback that's called when the response is ready to be modified.

map's first argument is the original response body. You should call done(null, modifiedBody) with the updated response body when you're ready to do so.

const distort = require('response-distort')
const http    = require('http')

http.createServer(function(req, res) {
  distort(res, function(body, done) {
    done(null, body.toUpperCase())
  })

  // handle the response as normal...
}).listen(function() {
  // ...
})

License

MIT. See LICENSE.md for details.