A node.js proxy server that dispatches requests to downstream servers depending on the path and/or host.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
LICENSE
Makefile
README.md

README.md

Dispatj

A server that proxies requests to downstream servers depending on the request path in about 60 lines of JavaScript. It's like Apache with mod_proxy, only simpler.

Usage

This example will proxy requests on any host to a path beginning with /foo to port 8088 on localhost, and to a path beginning with /bar to port 80 on 10.0.0.4:

var dispatj = require('dispatj'),
    sys = require('sys');

var mappings = [
  { matchPath: '^/foo', port: 8088 },
  { matchPath: '^/bar', host: '10.0.0.4' }
];

var listenPort = 8080;

dispatj.run(mappings, listenPort, sys.log);

Mappings

The following keys can be specified in a mapping:

  • matchPath — Regular expression which request path must match. Default: match any path.
  • matchHost — Regular expression which request host must match. Default: match any host.
  • host — Proxy the request to this host. Default: localhost.
  • port — Proxy the request to this port. Default: 80.

Prerequisites

To run the tests, you will also need:

All dependencies can be installed via npm.