11import type * as net from 'net' ;
22import type * as http from 'http' ;
33import type * as https from 'https' ;
4- import type { RequestHandler , Options , Filter } from './types' ;
4+ import type { RequestHandler , Options , Filter , Logger } from './types' ;
55import * as httpProxy from 'http-proxy' ;
66import { verifyConfig } from './configuration' ;
77import { getPlugins } from './get-plugins' ;
@@ -10,17 +10,20 @@ import * as PathRewriter from './path-rewriter';
1010import * as Router from './router' ;
1111import { Debug as debug } from './debug' ;
1212import { getFunctionName } from './utils/function' ;
13+ import { getLogger } from './logger' ;
1314
1415export class HttpProxyMiddleware < TReq , TRes > {
1516 private wsInternalSubscribed = false ;
1617 private serverOnCloseSubscribed = false ;
1718 private proxyOptions : Options < TReq , TRes > ;
1819 private proxy : httpProxy < TReq , TRes > ;
1920 private pathRewriter ;
21+ private logger : Logger ;
2022
2123 constructor ( options : Options < TReq , TRes > ) {
2224 verifyConfig < TReq , TRes > ( options ) ;
2325 this . proxyOptions = options ;
26+ this . logger = getLogger ( options as unknown as Options ) ;
2427
2528 debug ( `create proxy server` ) ;
2629 this . proxy = httpProxy . createProxyServer ( { } ) ;
@@ -109,7 +112,13 @@ export class HttpProxyMiddleware<TReq, TRes> {
109112 pathFilter : Filter < TReq > | undefined ,
110113 req : http . IncomingMessage ,
111114 ) : 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+ }
113122 } ;
114123
115124 /**
0 commit comments