Reverse proxy with Zappa
Zappa is a Node.js / Express.js web server and framework based on the ideas of Sinatra.
One of the many uses I have had for Zappa includes mixing dynamic content and reverse proxying other Zappa processes and CouchDB. The main tool here is the request module and a recent (0.6+) version of Node.js.
Here a short example (in CoffeeScript):
require('zappajs').run, -> request = require 'request' make_proxy = (proxy_base) -> return -> proxy = request uri: proxy_base + @request.url method: @request.method headers: @request.headers jar: false followRedirect: false timeout: 1000 @request.pipe proxy proxy.pipe @response return couchdb_proxy = make_proxy 'http://127.0.0.1:5984' couchdb_urls = /^\/(_session|_users|_uuids|_utils|provisioning|billing|cdr|u.*)($|\/)/ @get couchdb_urls, couchdb_proxy @post couchdb_urls, couchdb_proxy @put couchdb_urls, couchdb_proxy @del couchdb_urls, couchdb_proxy
The make_proxy function is a generic reverse proxy for Zappa, and since there isn't really anything specific to Zappa here, can probably be used in Express.js as well. posted: 2012-02-06 10:14 edit: 2013-04-04: should not follow redirects. tags: zappa