Skip to content

Commit 810b69a

Browse files
committed
[fix] fallback to next middleware if there is no rule.
[doc] add readme
1 parent d5b3400 commit 810b69a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ module.exports = function (urls) {
4747
// If routing to a server on another domain, the hostname in the request must be changed.
4848
req.headers.host = m.host;
4949
// Once any changes are taken care of, this line makes the magic happen.
50-
proxy.proxyRequest(req, res, m.dest);
50+
return proxy.proxyRequest(req, res, m.dest);
5151
}
5252
}
53+
next() //did not have a rule for this request. fall back to next middleware.
5354
}
5455
}

readme.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#proxy by url
2+
3+
this is a simple example of a node-http-middleware that will proxy based on the incoming url.
4+
say you want to proxy every request thing under /database to localhost:5984 (couchbd)
5+
(and remove the /database prefix)
6+
7+
this is how:
8+
9+
require('http-proxy').createServer(
10+
require('proxy-by-url')({
11+
'/database': { port: 5984, host: 'localhost' },
12+
})
13+
).listen(8000)

0 commit comments

Comments
 (0)