Permalink
Browse files

[fix] fallback to next middleware if there is no rule.

[doc] add readme
  • Loading branch information...
1 parent d5b3400 commit 810b69a3dcf9f944a2b74973953ffdb729714259 @dominictarr committed Jul 30, 2011
Showing with 15 additions and 1 deletion.
  1. +2 −1 index.js
  2. +13 −0 readme.markdown
View
@@ -47,8 +47,9 @@ module.exports = function (urls) {
// If routing to a server on another domain, the hostname in the request must be changed.
req.headers.host = m.host;
// Once any changes are taken care of, this line makes the magic happen.
- proxy.proxyRequest(req, res, m.dest);
+ return proxy.proxyRequest(req, res, m.dest);
}
}
+ next() //did not have a rule for this request. fall back to next middleware.
}
}
View
@@ -0,0 +1,13 @@
+#proxy by url
+
+this is a simple example of a node-http-middleware that will proxy based on the incoming url.
+say you want to proxy every request thing under /database to localhost:5984 (couchbd)
+(and remove the /database prefix)
+
+this is how:
+
+ require('http-proxy').createServer(
+ require('proxy-by-url')({
+ '/database': { port: 5984, host: 'localhost' },
+ })
+ ).listen(8000)

0 comments on commit 810b69a

Please sign in to comment.