node package manager



What is it?

A small wrapper around request ( that eases proxying services.


myApp proxies all calls to myService with the same URL scheme used except for all calls proxied to myService have a "/service" prepended to the url.
app.get '/service/resource', serviceController.proxy '/service/resource', serviceController.proxy
ServiceProxy = require 'service_proxy'
serviceProxy = new ServiceProxy {
  host: "http://localhost:4001"
  transformUrl: (host, path) ->
    return host + path.replace "/service", ""
  onError: (req, res) ->
    res.send err.message, 500
module.exports.proxy = (req, res) ->
  serviceProxy.proxy req, res, { requestOpts: {json: true} }


Can either be used as a static method:

ServiceProxy.proxy req, res, opts

or as a class as in the example above


host: the hostname to proxy to (is not required, can be done in transformUrl) transformUrl: a function that returns the route to the service, gets passed the host and request path onError: a function to run when a pipe error occurs requestOpts: a hash of options to be passed to request