Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including host-proxy with all npm packages installed. Try it out:

var hostProxy = require("host-proxy")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

host-proxy v1.0.2

Fast, lightweight and transparent http(s) proxy that supports dynamic hostnames.

HOST-PROXY

Fast, lightweight and transparent http(s) proxy that supports dynamic hostnames.

Installation

Npm

npm install host-proxy

Example

var createProxy = require('host-proxy');

// Start a proxy server.
createProxy(function (hostname, secure) {
    // Respond with an address to proxy to.
    // Result is passed to net.createConnection.
    return ({
        "test.com": "http://localhost:3002",
        "secure.test.com": "https://localhost:3003",
        "search.test.com": "http://google.ca",
        "api.test.com": { port: 12345, family: 'IPv4', address: "127.0.0.1" }
    })[hostname];
}).listen(80);

The above example creates the following proxy:

  • test.com -> http://localhost:3002
  • secure.test.com -> https://localhost:3003
  • search.test.com -> http://google.ca
  • api.test.com -> http://localhost:12345

Contributions

  • Use npm to run tests.

Please feel free to create a PR!

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free