From 8de28aafeff3854e416dbeac1a1fc1c483c0de7d Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Mon, 22 Aug 2022 20:13:14 -0700 Subject: [PATCH 1/3] Remove trailing slash in proxyUrl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Infura has trouble handling requests with a trailing slash in API endpoint. https://github.com/INFURA/infura/issues/221 Credit to 🍯 for the find --- src/server.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server.mjs b/src/server.mjs index 8bfbdc7..ae9b1cd 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -46,6 +46,7 @@ function getReqBody(req) { async function proxy(host, request, reqBody, response) { let pathname = url.parse(request.url).pathname; + pathname = pathname === "/" ? "" : pathname; // to avoid a trailing slash let hostname = url.parse(host).host; let proxyUrl = `${host}${pathname}`; let reqMethod = request.method; From eb7e52491fb790877f732b3181242477c56c6398 Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Tue, 23 Aug 2022 10:39:27 -0700 Subject: [PATCH 2/3] Remove trailing slashes directly from proxyUrl --- src/server.mjs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/server.mjs b/src/server.mjs index ae9b1cd..ba437a0 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -46,9 +46,8 @@ function getReqBody(req) { async function proxy(host, request, reqBody, response) { let pathname = url.parse(request.url).pathname; - pathname = pathname === "/" ? "" : pathname; // to avoid a trailing slash let hostname = url.parse(host).host; - let proxyUrl = `${host}${pathname}`; + let proxyUrl = `${host}${pathname}`.replace(/\/+$/, ""); // remove trailing slashes let reqMethod = request.method; let reqHeaders = { ...request.headers, From 6565bad2c218fe7f584af7177f494a8d98d6579d Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Tue, 23 Aug 2022 10:50:05 -0700 Subject: [PATCH 3/3] Revert latest change --- src/server.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server.mjs b/src/server.mjs index ba437a0..ae9b1cd 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -46,8 +46,9 @@ function getReqBody(req) { async function proxy(host, request, reqBody, response) { let pathname = url.parse(request.url).pathname; + pathname = pathname === "/" ? "" : pathname; // to avoid a trailing slash let hostname = url.parse(host).host; - let proxyUrl = `${host}${pathname}`.replace(/\/+$/, ""); // remove trailing slashes + let proxyUrl = `${host}${pathname}`; let reqMethod = request.method; let reqHeaders = { ...request.headers,