Skip to content

Commit c82d5e8

Browse files
committed
update README wrt proxyReqPathResolver
1 parent f6b344f commit c82d5e8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,35 @@ eventually calls
5353
next('An arbitrary rejection messasage');
5454
```
5555

56+
### Host
5657

58+
The first positional argument is for the proxy host; in many cases you will use a static string here, eg.
5759

60+
```
61+
app.use('/', proxy('http://google.com'))
62+
```
63+
64+
However, this argument can also be a function, and that function can be
65+
memoized or computed on each request, based on the setting of
66+
```memoizeHost```.
67+
68+
```
69+
function selectProxyHost() {
70+
return (new Date() % 2) ? 'http://google.com' : 'http://altavista,com';
71+
}
72+
73+
app.use('/', proxy(selectProxyHost);
74+
```
5875

5976
### Options
6077

6178
#### proxyReqPathResolver (supports Promises)
6279

80+
Note: In ```express-http-proxy```, the ```path``` is considered the portion of
81+
the url after the host, and including all query params. E.g. for the URL
82+
```http://smoogle.com/search/path?q=123```; the path is
83+
```/search/path?q=123```.
84+
6385
Provide a proxyReqPathResolver function if you'd like to
6486
operate on the path before issuing the proxy request. Use a Promise for async
6587
operations.
@@ -79,7 +101,8 @@ app.use('/proxy', proxy('localhost:12345', {
79101
proxyReqPathResolver: function(req) {
80102
return new Promise(function (resolve, reject) {
81103
setTimeout(function () { // simulate async
82-
var resolvedPathValue = "http://google.com";
104+
// in this case I expect a request to /proxy => localhost:12345/a/different/path
105+
var resolvedPathValue = "/a/different/path";
83106
resolve(resolvedPathValue);
84107
}, 200);
85108
});

0 commit comments

Comments
 (0)