National Pest Management

    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/camouflage-rewrite package

    1.5.0 • Public • Published


    Express middleware to rewrite a request to a different URL and optional also replace it in the response content. This middleware replaces the Host header field and the requested path with given URL. All middlewares used after the rewrite middleware will see the patched header field in req.headers and the patched path in baseUrl and originalUrl. Optional it's also possible to rewrite the response content. The res object is hijacked to pipe the response stream through a string replacement transform. No code changes in the other middlewares or handlers are required. The proxy header fields X-Forwarded-Host and X-Forwarded-Proto are used to support https: URLs.


    The module returns a function to build a middleware. The function must be called with a single options object. The following options are supported:

    • mediaTypes: An array of media types which will be processed. The Accept header field is used for the test. (optional)
    • rewriteContent: If it's set to true the response content will be also rewritten.
    • rewriteHeaders: If it's set to true the response headers will be also rewritten.
    • url: The internal/camouflage URL which will replace the request URL.


    // load the module
    var rewrite = require('camouflage-rewrite')
    // add the routing
      rewriteContent: true,
      url: ''
    app.use(function (req, res) {
      // internal the variables will have the following values:
      console.log( //
      console.log(req.baseUrl) // /base
      // the response to '' will be patched like this
      res.end('') //


    npm i camouflage-rewrite

    DownloadsWeekly Downloads






    Unpacked Size

    17.4 kB

    Total Files


    Last publish


    • ktk
    • bergos
    • ludovicm67
    • zazuko-bot