From 92168ee392a66c9a8a0ec27859f0400794a579ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Sun, 10 May 2020 08:55:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#44608=20fix(expres?= =?UTF-8?q?s-http-proxy):=20correct=20`filter`=20method=20definition=20by?= =?UTF-8?q?=20@peterblazejewicz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This correct return type of the `filter` method to allow returning a promise as per public documentation: https://github.com/villadora/express-http-proxy#filter-supports-promises /cc @ignaciocaff Thanks! Fixes #44550 --- types/express-http-proxy/express-http-proxy-tests.ts | 7 +++++++ types/express-http-proxy/index.d.ts | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/types/express-http-proxy/express-http-proxy-tests.ts b/types/express-http-proxy/express-http-proxy-tests.ts index 0f2f69d025..4f68381f96 100644 --- a/types/express-http-proxy/express-http-proxy-tests.ts +++ b/types/express-http-proxy/express-http-proxy-tests.ts @@ -106,6 +106,13 @@ proxy("www.google.com", { return req.method === "GET"; } }); +proxy("www.google.com", { + filter: (req, res) => { + return new Promise(resolve => { + resolve(req.method === 'GET'); + }); + } +}); proxy("www.google.com", { memoizeHost: true diff --git a/types/express-http-proxy/index.d.ts b/types/express-http-proxy/index.d.ts index 201f1334dd..c74a3353af 100644 --- a/types/express-http-proxy/index.d.ts +++ b/types/express-http-proxy/index.d.ts @@ -43,7 +43,11 @@ declare namespace proxy { userReq: Request, userRes: Response ) => Buffer | string | Promise; - filter?: (req: Request, res: Response) => boolean; + /** + * The filter option can be used to limit what requests are proxied. + * Return true to continue to execute proxy; return false-y to skip proxy for this request. + */ + filter?: (req: Request, res: Response) => boolean | Promise; skipToNextHandlerFilter?: (proxyRes: Response) => boolean; proxyReqBodyDecorator?: (bodyContent: any, srcReq: Request) => any; preserveHostHdr?: boolean;