Skip to content

Commit 99306bc

Browse files
author
116-7
committed
Use WHATWG URL constructor, update const name to match field in URL object.
1 parent 37d9f00 commit 99306bc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/dev-middleware/src/inspector-proxy/InspectorProxy.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,21 @@ export default class InspectorProxy implements InspectorProxyQueries {
9494
response: ServerResponse,
9595
next: (?Error) => mixed,
9696
) {
97-
const path = url.parse(request.url).pathname;
97+
// When request.url is a relative path, the WHATWG URL constructor will require
98+
// the second "base" param otherwise an exception will be thrown.
99+
// We could use `http://${request.headers.host}` here instead however:
100+
// - We are forced to make an assumption about the scheme so if someone is running
101+
// Metro over https it could cause confusion.
102+
//
103+
// - We are only extracting pathname from the parsed URL so the host portion is
104+
// irrelevant.
105+
const pathname = new URL(request.url, 'http://example').pathname;
98106
if (
99-
path === PAGES_LIST_JSON_URL ||
100-
path === PAGES_LIST_JSON_URL_2
107+
pathname === PAGES_LIST_JSON_URL ||
108+
pathname === PAGES_LIST_JSON_URL_2
101109
) {
102110
this._sendJsonResponse(response, this.getPageDescriptions());
103-
} else if (path === PAGES_LIST_JSON_VERSION_URL) {
111+
} else if (pathname === PAGES_LIST_JSON_VERSION_URL) {
104112
this._sendJsonResponse(response, {
105113
Browser: 'Mobile JavaScript',
106114
'Protocol-Version': '1.1',

0 commit comments

Comments
 (0)