From 9165d80955237cd7c481465843933f806ab59a78 Mon Sep 17 00:00:00 2001 From: brettcave Date: Fri, 29 Jun 2012 05:52:30 -0700 Subject: [PATCH] Created Routing proxy with access logging (markdown) --- Routing-proxy-with-access-logging.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Routing-proxy-with-access-logging.md diff --git a/Routing-proxy-with-access-logging.md b/Routing-proxy-with-access-logging.md new file mode 100644 index 0000000..0a0f36b --- /dev/null +++ b/Routing-proxy-with-access-logging.md @@ -0,0 +1,21 @@ +One of the useful methods of running http-proxy is as a routing proxy. The following configuration will configure http-proxy as a routing proxy with an access logger. In the example, http-proxy routes to 2 node applications, listening on port 3010 and 3020 respectively: + + var httpProxy = require('http-proxy'); + + var options = { router: { + '/page1$' : localhost:3010, + '/page2$' : localhost:3020, + // default route + '.*' : localhost:3020 + }} + + var router = new httpProxy.RoutingProxy(options); + var proxy = httpProxy.createServer(function(req,res) { + console.log("request: " + req.path + "; method: " + req.method); + router.proxyRequest(req,res); + }); + + proxy.listen(3000, function() { console.log("Routing proxy listening on " + proxy.addresss().port); }); + +the above example uses console.log, but you could use any logging library, e.g. winston, to create access logs with info from req and res. +