Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

camouflage-rewrite

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

camouflage-rewrite

Express middleware to rewrite a request to a different URL and optional also replace it in the response content

  • 1.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

camouflage-rewrite

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.

Usage

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.

Example

// load the module
var rewrite = require('camouflage-rewrite')

// add the routing
app.use(rewrite({
  rewriteContent: true,
  url: 'http://example.com/base/'
})

app.use(function (req, res) {
  // internal the variables will have the following values:
  console.log(req.headers.host) // example.com
  console.log(req.baseUrl) // /base

  // the response to 'http://example.org/path' will be patched like this
  res.end('http://example.com/base/path') // http://example.org/path
})

Keywords

FAQs

Package last updated on 08 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc