a cute little http proxy server
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
img
lib
README.md
package.json
proxy.js

README.md

My Little Proxy

Example:

proxy.js

var myLittleProxy = require('./lib/my-little-proxy');

// Turn on cli logger (powered by logref)
myLittleProxy.cli();

// Mirrors the basic http-proxy api but with `this` scoped to a collection
// of helpful little things
myLittleProxy(function (req, res, proxy) {
  if (this.rewrite('/couchdb', '/')) {
    return this.forward('localhost', 5984);
  }
  this.end();
}).listen(8000);

output:

Things MLP Currently Supports:

this.host(hostMatch, [port])

Pattern match against the Host header (ex: '*.jesusabdullah.net') with an optional port argument (to match against the Host header's port).

this.rewrite(from, to)

Rewrite paths from one root to another (similar to how couch does it). Returns true if the rewrite matches/applies.

this.forward(host, port)

A thin wrapper around proxyRequest. Only takes host/port args as positionals, and logs the event.

this.withResponseBody(function(buffer, write))

A shim for res.write which allows for modifying the write on its way out. write is a callback with signature function(buffer).

this.withResponseHeader(function (code, headers, writeHead) {

A shim for res.writeHead which allows for modifying the response code and headers. writeHead is a callback with signature function (code, [humanReason], headers).

this.notFound()

End the request with a generic (JSON-parseable, human-readable) 404.

License:

MIT/X11.