1
1
import type * as net from 'net' ;
2
2
import type * as http from 'http' ;
3
3
import type * as https from 'https' ;
4
- import type { RequestHandler , Options , Filter } from './types' ;
4
+ import type { RequestHandler , Options , Filter , Logger } from './types' ;
5
5
import * as httpProxy from 'http-proxy' ;
6
6
import { verifyConfig } from './configuration' ;
7
7
import { getPlugins } from './get-plugins' ;
@@ -10,17 +10,20 @@ import * as PathRewriter from './path-rewriter';
10
10
import * as Router from './router' ;
11
11
import { Debug as debug } from './debug' ;
12
12
import { getFunctionName } from './utils/function' ;
13
+ import { getLogger } from './logger' ;
13
14
14
15
export class HttpProxyMiddleware < TReq , TRes > {
15
16
private wsInternalSubscribed = false ;
16
17
private serverOnCloseSubscribed = false ;
17
18
private proxyOptions : Options < TReq , TRes > ;
18
19
private proxy : httpProxy < TReq , TRes > ;
19
20
private pathRewriter ;
21
+ private logger : Logger ;
20
22
21
23
constructor ( options : Options < TReq , TRes > ) {
22
24
verifyConfig < TReq , TRes > ( options ) ;
23
25
this . proxyOptions = options ;
26
+ this . logger = getLogger ( options as unknown as Options ) ;
24
27
25
28
debug ( `create proxy server` ) ;
26
29
this . proxy = httpProxy . createProxyServer ( { } ) ;
@@ -109,7 +112,13 @@ export class HttpProxyMiddleware<TReq, TRes> {
109
112
pathFilter : Filter < TReq > | undefined ,
110
113
req : http . IncomingMessage ,
111
114
) : boolean => {
112
- return matchPathFilter ( pathFilter , req . url , req ) ;
115
+ try {
116
+ return matchPathFilter ( pathFilter , req . url , req ) ;
117
+ } catch ( err ) {
118
+ debug ( 'Error: matchPathFilter() called with request url: ' , `"${ req . url } "` ) ;
119
+ this . logger . error ( err ) ;
120
+ return false ;
121
+ }
113
122
} ;
114
123
115
124
/**
0 commit comments