Socket
Socket
Sign inDemoInstall

proxy-middleware

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    proxy-middleware

http(s) proxy as connect middleware


Version published
Weekly downloads
336K
decreased by-17.16%
Maintainers
1
Install size
8.73 kB
Created
Weekly downloads
 

Readme

Source

Build Status

Usage:

var connect = require('connect');
var url = require('url');
var proxy = require('proxy-middleware');

var app = connect();
app.use('/api', proxy(url.parse('https://example.com/endpoint')));
// now requests to '/api/x/y/z' are proxied to 'https://example.com/endpoint/x/y/z'

//same as example above but also uses a short hand string only parameter
app.use('/api-string-only', proxy('https://example.com/endpoint'));

Documentation:

proxyMiddleware(options)

options allows any options that are permitted on the http or https request options.

Other options:

  • route: you can pass the route for connect middleware within the options, as well.
  • via: by default no via header is added. If you pass true for this option the local hostname will be used for the via header. You can also pass a string for this option in which case that will be used for the via header.
  • cookieRewrite: this option can be used to support cookies via the proxy by rewriting the cookie domain to that of the proxy server. By default cookie domains are not rewritten. The cookieRewrite option works as the via option - if you pass true the local hostname will be used, and if you pass a string that will be used as the rewritten cookie domain.
  • preserveHost: When enabled, this option will pass the Host: line from the incoming request to the proxied host. Default: false.

Usage with route:

var proxyOptions = url.parse('https://example.com/endpoint');
proxyOptions.route = '/api';

var middleWares = [proxy(proxyOptions) /*, ...*/];

// Grunt connect uses this method
connect(middleWares);

Keywords

FAQs

Last updated on 24 Oct 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc