@@ -7,7 +7,7 @@ import type * as http from 'http';
77
88export function matchPathFilter < TReq = http . IncomingMessage > (
99 pathFilter : Filter < TReq > = '/' ,
10- uri : string ,
10+ uri : string | undefined ,
1111 req : http . IncomingMessage
1212) : boolean {
1313 // single path
@@ -34,8 +34,8 @@ export function matchPathFilter<TReq = http.IncomingMessage>(
3434
3535 // custom matching
3636 if ( typeof pathFilter === 'function' ) {
37- const pathname = getUrlPathName ( uri ) ;
38- return pathFilter ( pathname , req as unknown as TReq ) ;
37+ const pathname = getUrlPathName ( uri ) as string ;
38+ return pathFilter ( pathname , req as TReq ) ;
3939 }
4040
4141 throw new Error ( ERRORS . ERR_CONTEXT_MATCHER_GENERIC ) ;
@@ -46,18 +46,18 @@ export function matchPathFilter<TReq = http.IncomingMessage>(
4646 * @param {String } uri 'http://example.org/api/b/c/d.html'
4747 * @return {Boolean }
4848 */
49- function matchSingleStringPath ( pathFilter : string , uri : string ) {
49+ function matchSingleStringPath ( pathFilter : string , uri ? : string ) {
5050 const pathname = getUrlPathName ( uri ) ;
51- return pathname . indexOf ( pathFilter ) === 0 ;
51+ return pathname ? .indexOf ( pathFilter ) === 0 ;
5252}
5353
54- function matchSingleGlobPath ( pattern : string | string [ ] , uri : string ) {
55- const pathname = getUrlPathName ( uri ) ;
54+ function matchSingleGlobPath ( pattern : string | string [ ] , uri ? : string ) {
55+ const pathname = getUrlPathName ( uri ) as string ;
5656 const matches = micromatch ( [ pathname ] , pattern ) ;
5757 return matches && matches . length > 0 ;
5858}
5959
60- function matchMultiGlobPath ( patternList : string | string [ ] , uri : string ) {
60+ function matchMultiGlobPath ( patternList : string | string [ ] , uri ? : string ) {
6161 return matchSingleGlobPath ( patternList , uri ) ;
6262}
6363
@@ -66,7 +66,7 @@ function matchMultiGlobPath(patternList: string | string[], uri: string) {
6666 * @param {String } uri 'http://example.org/api/b/c/d.html'
6767 * @return {Boolean }
6868 */
69- function matchMultiPath ( pathFilterList : string [ ] , uri : string ) {
69+ function matchMultiPath ( pathFilterList : string [ ] , uri ? : string ) {
7070 let isMultiPath = false ;
7171
7272 for ( const context of pathFilterList ) {
@@ -85,7 +85,7 @@ function matchMultiPath(pathFilterList: string[], uri: string) {
8585 * @param {String } uri from req.url
8686 * @return {String } RFC 3986 path
8787 */
88- function getUrlPathName ( uri : string ) {
88+ function getUrlPathName ( uri ? : string ) {
8989 return uri && url . parse ( uri ) . pathname ;
9090}
9191
0 commit comments