diff --git a/src/path-filter.ts b/src/path-filter.ts index e174146a..9790336b 100644 --- a/src/path-filter.ts +++ b/src/path-filter.ts @@ -36,7 +36,7 @@ export function matchPathFilter = | string | string[] - | ((pathname: string, req: TReq) => boolean); + | ((pathname: string, req: TReq) => boolean | string | RegExpMatchArray | null); /** * @see {@link https://github.com/chimurai/http-proxy-middleware/tree/master#defineplugin-helper `definePlugin()`} to define a http-proxy-middleware plugin. diff --git a/test/types.spec.ts b/test/types.spec.ts index 7114c4dd..9df4c59d 100644 --- a/test/types.spec.ts +++ b/test/types.spec.ts @@ -52,6 +52,24 @@ describe('http-proxy-middleware TypeScript Types', () => { expect(proxy).toBeDefined(); }); + it('should create proxy with truthy filter', () => { + const proxy = middleware({ + ...options, + pathFilter: (path, req) => path.match('^/api') && req.method === 'GET', + }); + expect(proxy).toBeDefined(); + }); + + it('should create proxy with truthy regex match filter', () => { + const proxy = middleware({ ...options, pathFilter: (path, req) => path.match('^/api') }); + expect(proxy).toBeDefined(); + }); + + it('should create proxy with truthy regex test filter', () => { + const proxy = middleware({ ...options, pathFilter: (path, req) => /^\/api/.test(path) }); + expect(proxy).toBeDefined(); + }); + it('should create proxy with manual websocket upgrade function', () => { const proxy = middleware({ ...options, pathFilter: (path, req) => true }); expect(proxy.upgrade).toBeDefined();