GithubHelp home page GithubHelp logo

qurio-za / bouncy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sequoiar/bouncy

0.0 2.0 0.0 276 KB

bounce HTTP requests around for load balancing or as an HTTP host router

License: Other

bouncy's Introduction

bouncy

pipe raw http traffic from incoming http requests to remote endpoints

build status

trampoline

example

route.js

Route requests based on the host field to servers on ports 8001 and 8002:

var bouncy = require('bouncy');

var server = bouncy(function (req, res, bounce) {
    if (req.headers.host === 'beep.example.com') {
        bounce(8001);
    }
    else if (req.headers.host === 'boop.example.com') {
        bounce(8002);
    }
    else {
        res.statusCode = 404;
        res.end('no such host');
    }
});
server.listen(8000);

var server = bouncy(opts={}, cb)

bouncy(cb) returns a new net.Server object that you can .listen() on.

If you specify opts.key and opts.cert, the connection will be set to secure mode using tls. Do this if you want to make an https router.

If the arity of cb is 3, you'll get the response object res in cb(req, res, bounce). Otherwise you just get cb(req, bounce).

If you are using more than one SSL cert, add opts.SNICallback. See the example http-https-sni.js and the nodejs tls page for details.

bounce(stream, opts={})

Call this function when you're ready to bounce the request to a stream.

The exact request that was received will be written to stream and future incoming data will be piped to and from it.

To send data to a different url path on the destination stream, you can specify opts.path.

To change the http verb you can set opts.method.

You can specify header fields to insert into the request with opts.headers.

bounce() returns the stream object that it uses to connect to the remote host.

bounce(port, ...), bounce(host, port, ...), bounce(url)

These variants of bounce() are sugar for bounce(net.connect(port)) and bounce(net.connect(port, host)).

Optionally you can pass port and host keys to opts and it does the same thing.

Passing bounce() a string that looks like a url (with or without "http://") will set the opts.host, opts.port, and opts.path accordingly.

usage

usage: bouncy FILE PORT

Create a routes FILE like this:

  {
    "beep.example.com" : 8000,
    "boop.example.com" : 8001
  }

Then point the `bouncy` command at this `routes.json` file and give it
a port to listen on: 

  bouncy routes.json 80

The `routes.json` file should just map host names to host/port combos. Use a
colon-separated string to specify a host and port in a route.

Use `""` for the host as a default route.

You can optionally specify a listen address as the third parameter or with
`--address`. It defaults to `0.0.0.0`. Specify `::` to listen on both IPv4 and
IPv6 addresses.

install

With npm, to get the library do:

npm install bouncy

or to install the command-line tool do:

npm install -g bouncy

license

MIT

bouncy's People

Contributors

sethml avatar shripadk avatar tenzer avatar yorickvp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.