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
The forwarding option can be used in conjunction with the proxy table options by simply including both the 'forward' and 'router' properties in the options passed to 'createServer'.
219
219
220
+
### Listening for proxy events
221
+
Sometimes you want to listen to an event on a proxy. For example, you may want to listen to the 'end' event, which represents when the proxy has finished proxying a request.
222
+
223
+
```js
224
+
var httpProxy =require('http-proxy');
225
+
226
+
var server =httpProxy.createServer(function (req, res, proxy) {
227
+
228
+
var buffer =httpProxy.buffer(req);
229
+
230
+
proxy.proxyRequest(req, res, {
231
+
host:'127.0.0.1',
232
+
port:9000,
233
+
buffer: buffer
234
+
});
235
+
236
+
});
237
+
238
+
server.proxy.on('end', function() {
239
+
console.log("The request was proxied.");
240
+
});
241
+
242
+
server.listen(8000);
243
+
```
244
+
245
+
It's important to remember not to listen for events on the proxy object in the function passed to `httpProxy.createServer`. Doing so would add a new listener on every request, which would end up being a disaster.
220
246
221
247
## Using HTTPS
222
248
You have all the full flexibility of node-http-proxy offers in HTTPS as well as HTTP. The two basic scenarios are: with a stand-alone proxy server or in conjunction with another HTTPS server.
0 commit comments