@@ -53,13 +53,35 @@ eventually calls
5353next('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+
6385Provide a proxyReqPathResolver function if you'd like to
6486operate on the path before issuing the proxy request. Use a Promise for async
6587operations.
@@ -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