From 37d9f0038cdc7b56d2507a1fbff22b789724655f Mon Sep 17 00:00:00 2001 From: 116-7 <1167@local> Date: Mon, 16 Oct 2023 23:59:25 +1100 Subject: [PATCH 1/3] Refactors InspectorProxy to compare pathname portion of url passed in request to local pathname comparator variables to fix issue with other rightward elements of url such as query or fragment entering the comparison and causing 404 errors for key debugging routes. --- .../dev-middleware/src/inspector-proxy/InspectorProxy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index be4fe3e13a966e..d17a1742335afe 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -94,12 +94,13 @@ export default class InspectorProxy implements InspectorProxyQueries { response: ServerResponse, next: (?Error) => mixed, ) { + const path = url.parse(request.url).pathname; if ( - request.url === PAGES_LIST_JSON_URL || - request.url === PAGES_LIST_JSON_URL_2 + path === PAGES_LIST_JSON_URL || + path === PAGES_LIST_JSON_URL_2 ) { this._sendJsonResponse(response, this.getPageDescriptions()); - } else if (request.url === PAGES_LIST_JSON_VERSION_URL) { + } else if (path === PAGES_LIST_JSON_VERSION_URL) { this._sendJsonResponse(response, { Browser: 'Mobile JavaScript', 'Protocol-Version': '1.1', From 99306bcd41dbbd6b06f567d5442cfd54186b87f8 Mon Sep 17 00:00:00 2001 From: 116-7 <1167@local> Date: Tue, 17 Oct 2023 08:37:14 +1100 Subject: [PATCH 2/3] Use WHATWG URL constructor, update const name to match field in URL object. --- .../src/inspector-proxy/InspectorProxy.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index d17a1742335afe..9b6252f330b170 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -94,13 +94,21 @@ export default class InspectorProxy implements InspectorProxyQueries { response: ServerResponse, next: (?Error) => mixed, ) { - const path = url.parse(request.url).pathname; + // When request.url is a relative path, the WHATWG URL constructor will require + // the second "base" param otherwise an exception will be thrown. + // We could use `http://${request.headers.host}` here instead however: + // - We are forced to make an assumption about the scheme so if someone is running + // Metro over https it could cause confusion. + // + // - We are only extracting pathname from the parsed URL so the host portion is + // irrelevant. + const pathname = new URL(request.url, 'http://example').pathname; if ( - path === PAGES_LIST_JSON_URL || - path === PAGES_LIST_JSON_URL_2 + pathname === PAGES_LIST_JSON_URL || + pathname === PAGES_LIST_JSON_URL_2 ) { this._sendJsonResponse(response, this.getPageDescriptions()); - } else if (path === PAGES_LIST_JSON_VERSION_URL) { + } else if (pathname === PAGES_LIST_JSON_VERSION_URL) { this._sendJsonResponse(response, { Browser: 'Mobile JavaScript', 'Protocol-Version': '1.1', From d24916d08aa876e65c7e3e04b3ce6593e9c0f234 Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Tue, 17 Oct 2023 13:29:02 +0100 Subject: [PATCH 3/3] Switch back to Node's `url.parse` for cleaner handling of partial URLs. --- .../src/inspector-proxy/InspectorProxy.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index 9b6252f330b170..96d224a7cb19fb 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -94,15 +94,7 @@ export default class InspectorProxy implements InspectorProxyQueries { response: ServerResponse, next: (?Error) => mixed, ) { - // When request.url is a relative path, the WHATWG URL constructor will require - // the second "base" param otherwise an exception will be thrown. - // We could use `http://${request.headers.host}` here instead however: - // - We are forced to make an assumption about the scheme so if someone is running - // Metro over https it could cause confusion. - // - // - We are only extracting pathname from the parsed URL so the host portion is - // irrelevant. - const pathname = new URL(request.url, 'http://example').pathname; + const pathname = url.parse(request.url).pathname; if ( pathname === PAGES_LIST_JSON_URL || pathname === PAGES_LIST_JSON_URL_2