my-little-proxy

0.1.0 • Public • Published

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: '*.trashfire.xyz') 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.

/my-little-proxy/

    Package Sidebar

    Install

    npm i my-little-proxy

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT/X11

    Unpacked Size

    979 kB

    Total Files

    13

    Last publish

    Collaborators

    • jfhbrook