@@ -274,8 +274,8 @@ router: async function(req) {
274
274
### ` plugins ` (Array)
275
275
276
276
``` js
277
- const simpleRequestLogger = (proxy , options ) => {
278
- proxy .on (' proxyReq' , (proxyReq , req , res ) => {
277
+ const simpleRequestLogger = (proxyServer , options ) => {
278
+ proxyServer .on (' proxyReq' , (proxyReq , req , res ) => {
279
279
console .log (` [HPM] [${ req .method } ] ${ req .url } ` ); // outputs: [HPM] GET /users
280
280
});
281
281
},
@@ -323,9 +323,26 @@ function logProvider(provider) {
323
323
324
324
## ` http-proxy ` events
325
325
326
- Subscribe to [ http-proxy events] ( https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events ) :
326
+ Subscribe to [ http-proxy events] ( https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events ) with the ` on ` option :
327
327
328
- - ** option.onError** : function, subscribe to http-proxy's ` error ` event for custom error handling.
328
+ ``` js
329
+ createProxyMiddleware ({
330
+ target: ' http://www.example.org' ,
331
+ on: {
332
+ proxyReq : (proxyReq , req , res ) => {
333
+ /* handle proxyReq */
334
+ },
335
+ proxyRes : (proxyRes , req , res ) => {
336
+ /* handle proxyRes */
337
+ },
338
+ error : (err , req , res ) => {
339
+ /* handle error */
340
+ },
341
+ },
342
+ });
343
+ ```
344
+
345
+ - ** option.on.error** : function, subscribe to http-proxy's ` error ` event for custom error handling.
329
346
330
347
``` javascript
331
348
function onError (err , req , res , target ) {
@@ -336,7 +353,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
336
353
}
337
354
```
338
355
339
- - ** option.onProxyRes ** : function, subscribe to http-proxy's ` proxyRes ` event.
356
+ - ** option.on.proxyRes ** : function, subscribe to http-proxy's ` proxyRes ` event.
340
357
341
358
``` javascript
342
359
function onProxyRes (proxyRes , req , res ) {
@@ -345,7 +362,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
345
362
}
346
363
```
347
364
348
- - ** option.onProxyReq ** : function, subscribe to http-proxy's ` proxyReq ` event.
365
+ - ** option.on.proxyReq ** : function, subscribe to http-proxy's ` proxyReq ` event.
349
366
350
367
``` javascript
351
368
function onProxyReq (proxyReq , req , res ) {
@@ -355,7 +372,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
355
372
}
356
373
```
357
374
358
- - ** option.onProxyReqWs ** : function, subscribe to http-proxy's ` proxyReqWs ` event.
375
+ - ** option.on.proxyReqWs ** : function, subscribe to http-proxy's ` proxyReqWs ` event.
359
376
360
377
``` javascript
361
378
function onProxyReqWs (proxyReq , req , socket , options , head ) {
@@ -364,7 +381,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
364
381
}
365
382
```
366
383
367
- - ** option.onOpen ** : function, subscribe to http-proxy's ` open ` event.
384
+ - ** option.on.open ** : function, subscribe to http-proxy's ` open ` event.
368
385
369
386
``` javascript
370
387
function onOpen (proxySocket ) {
@@ -373,7 +390,7 @@ Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#li
373
390
}
374
391
```
375
392
376
- - ** option.onClose ** : function, subscribe to http-proxy's ` close ` event.
393
+ - ** option.on.close ** : function, subscribe to http-proxy's ` close ` event.
377
394
378
395
``` javascript
379
396
function onClose (res , socket , head ) {
0 commit comments