You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Express middleware to proxy request to another host and pass response back to original caller.
@@ -24,6 +24,51 @@ var app = require('express')();
24
24
app.use('/proxy', proxy('www.google.com'));
25
25
```
26
26
27
+
### 30k view
28
+
29
+
The proxy middleware:
30
+
* proxies request to your server to an arbitrary server, and
31
+
* provide hooks to decorate and filter requests to the proxy target, and
32
+
* provide hooks you to decorate and filter proxy responses before returning them to the client.
33
+
34
+
```
35
+
36
+
Client Express App Proxy Middleware Target Server
37
+
| | | |
38
+
| HTTP Request | | |
39
+
|-------------------------->| | |
40
+
| | Request | |
41
+
| |--------------------------->| |
42
+
| | | +------------------------+ |
43
+
| | | | Request Preprocessing | |
44
+
| | | | 1. filter requests | |
45
+
| | | | 2. resolve proxy host | |
46
+
| | | | 3. decorate proxy opts | |
47
+
| | | | 4. decorate proxy req | |
48
+
| | | | 5. resolve req path | |
49
+
| | | +------------------------+ |
50
+
| | | Forwarded Request |
51
+
| | |---------------------------->|
52
+
| | | |
53
+
| | | Response with Headers |
54
+
| | |<----------------------------|
55
+
| | | |
56
+
| | | +------------------------+ |
57
+
| | | | Response Processing | |
58
+
| | | | 1. skip to next? | |
59
+
| | | | 2. copy proxy headers | |
60
+
| | | | 3. decorate headers | |
61
+
| | | | 4. decorate response | |
62
+
| | | +------------------------+ |
63
+
| | | |
64
+
| | Modified Response | |
65
+
| |<---------------------------| |
66
+
| Final Response | | |
67
+
|<--------------------------| | |
68
+
| | | |
69
+
70
+
```
71
+
27
72
### Streaming
28
73
29
74
Proxy requests and user responses are piped/streamed/chunked by default.
@@ -74,7 +119,7 @@ function selectProxyHost() {
74
119
app.use('/', proxy(selectProxyHost));
75
120
```
76
121
77
-
Notie: Host is only the host name. Any params after in url will be ignored. For ``http://google.com/myPath`, ``myPath`` will be ignored because the host name is ``google.com``.
122
+
Notie: Host is only the host name. Any params after in url will be ignored. For ``http://google.com/myPath`, ``myPath`` will be ignored because the host name is ``google.com``.
78
123
See ``proxyReqPathResolver`` for more detailed path information.
79
124
80
125
@@ -172,17 +217,17 @@ Promise form:
172
217
173
218
```js
174
219
app.use(proxy('localhost:12346', {
175
-
filter:function (req, res) {
176
-
returnnewPromise(function (resolve) {
220
+
filter:function (req, res) {
221
+
returnnewPromise(function (resolve) {
177
222
resolve(req.method==='GET');
178
-
});
223
+
});
179
224
}
180
225
}));
181
226
```
182
227
183
228
Note that in the previous example, `resolve(false)` will execute the happy path
184
229
for filter here (skipping the rest of the proxy, and calling `next()`).
185
-
`reject()` will also skip the rest of proxy and call `next()`.
230
+
`reject()` will also skip the rest of proxy and call `next()`.
| 1.6.0 | Do gzip and gunzip aysyncronously. Test and documentation improvements, dependency updates. |
609
654
| 1.5.1 | Fixes bug in stringifying debug messages. |
610
655
| 1.5.0 | Fixes bug in `filter` signature. Fix bug in skipToNextHandler, add expressHttpProxy value to user res when skipped. Add tests for host as ip address. |
611
-
| 1.4.0 | DEPRECATED. Critical bug in the `filter` api.|
656
+
| 1.4.0 | DEPRECATED. Critical bug in the `filter` api.|
612
657
| 1.3.0 | DEPRECATED. Critical bug in the `filter` api. `filter` now supports Promises. Update linter to eslint. |
613
-
| 1.2.0 | Auto-stream when no decorations are made to req/res. Improved docs, fixes issues in maybeSkipToNexthandler, allow authors to manage error handling. |
658
+
| 1.2.0 | Auto-stream when no decorations are made to req/res. Improved docs, fixes issues in maybeSkipToNexthandler, allow authors to manage error handling. |
614
659
| 1.1.0 | Add step to allow response headers to be modified.
615
660
| 1.0.7 | Update dependencies. Improve docs on promise rejection. Fix promise rejection on body limit. Improve debug output. |
616
661
| 1.0.6 | Fixes preserveHostHdr not working, skip userResDecorator on 304, add maybeSkipToNext, test improvements and cleanup. |
0 commit comments