@react-native/dev-middleware
Advanced tools
Comparing version 0.77.0-nightly-20241120-a865975ce to 0.77.0-nightly-20241121-550b0c0ed
@@ -24,2 +24,3 @@ /** | ||
createMessageMiddleware: null | undefined | CreateCustomMessageHandlerFn; | ||
deviceRelativeBaseUrl: URL; | ||
serverRelativeBaseUrl: URL; | ||
@@ -26,0 +27,0 @@ }>; |
@@ -42,3 +42,7 @@ "use strict"; | ||
const PAGES_POLLING_INTERVAL = 1000; | ||
const REWRITE_HOSTS_TO_LOCALHOST = ["127.0.0.1", "10.0.2.2", "10.0.3.2"]; | ||
const REWRITE_HOSTS_TO_LOCALHOST = new Set([ | ||
"127.0.0.1", | ||
"10.0.2.2", | ||
"10.0.3.2", | ||
]); | ||
const FILE_PREFIX = "file://"; | ||
@@ -63,2 +67,3 @@ const REACT_NATIVE_RELOADABLE_PAGE_ID = "-1"; | ||
#connectedPageIds = new Set(); | ||
#deviceRelativeBaseUrl; | ||
#serverRelativeBaseUrl; | ||
@@ -77,2 +82,3 @@ constructor(deviceOptions) { | ||
serverRelativeBaseUrl, | ||
deviceRelativeBaseUrl, | ||
}) { | ||
@@ -85,2 +91,3 @@ this.#id = id; | ||
this.#serverRelativeBaseUrl = serverRelativeBaseUrl; | ||
this.#deviceRelativeBaseUrl = deviceRelativeBaseUrl; | ||
this.#deviceEventReporter = eventReporter | ||
@@ -504,12 +511,13 @@ ? new _DeviceEventReporter.default(eventReporter, { | ||
const serverRelativeUrl = new URL(sourceMapURL.href); | ||
for (const hostToRewrite of REWRITE_HOSTS_TO_LOCALHOST) { | ||
if (params.sourceMapURL.includes(hostToRewrite)) { | ||
payload.params.sourceMapURL = params.sourceMapURL.replace( | ||
hostToRewrite, | ||
"localhost" | ||
); | ||
debuggerInfo.originalSourceURLAddress = hostToRewrite; | ||
serverRelativeUrl.host = this.#serverRelativeBaseUrl.host; | ||
serverRelativeUrl.protocol = this.#serverRelativeBaseUrl.protocol; | ||
} | ||
if ( | ||
sourceMapURL.origin === this.#deviceRelativeBaseUrl.origin && | ||
REWRITE_HOSTS_TO_LOCALHOST.has(this.#deviceRelativeBaseUrl.hostname) | ||
) { | ||
const debuggerRelativeURL = new URL(sourceMapURL.href); | ||
debuggerRelativeURL.hostname = "localhost"; | ||
serverRelativeUrl.host = this.#serverRelativeBaseUrl.host; | ||
serverRelativeUrl.protocol = this.#serverRelativeBaseUrl.protocol; | ||
debuggerInfo.originalSourceURLAddress = | ||
this.#deviceRelativeBaseUrl.hostname; | ||
payload.params.sourceMapURL = debuggerRelativeURL.href; | ||
} | ||
@@ -532,13 +540,14 @@ try { | ||
const parsedUrl = this.#tryParseHTTPURL(originalParamsUrl); | ||
if (parsedUrl) { | ||
for (const hostToRewrite of REWRITE_HOSTS_TO_LOCALHOST) { | ||
if (parsedUrl.hostname === hostToRewrite) { | ||
parsedUrl.hostname = "localhost"; | ||
payload.params.url = parsedUrl.href; | ||
debuggerInfo.originalSourceURLAddress = hostToRewrite; | ||
parsedUrl.host = this.#serverRelativeBaseUrl.host; | ||
parsedUrl.protocol = this.#serverRelativeBaseUrl.protocol; | ||
serverRelativeUrl = parsedUrl.href; | ||
} | ||
} | ||
if ( | ||
parsedUrl && | ||
parsedUrl.origin === this.#deviceRelativeBaseUrl.origin && | ||
REWRITE_HOSTS_TO_LOCALHOST.has(this.#deviceRelativeBaseUrl.hostname) | ||
) { | ||
parsedUrl.hostname = "localhost"; | ||
payload.params.url = parsedUrl.href; | ||
debuggerInfo.originalSourceURLAddress = | ||
this.#deviceRelativeBaseUrl.hostname; | ||
parsedUrl.host = this.#serverRelativeBaseUrl.host; | ||
parsedUrl.protocol = this.#serverRelativeBaseUrl.protocol; | ||
serverRelativeUrl = parsedUrl.href; | ||
} | ||
@@ -545,0 +554,0 @@ if (payload.params.url.match(/^[0-9a-z]+$/)) { |
@@ -144,2 +144,4 @@ "use strict"; | ||
const appName = query.app || "Unknown"; | ||
const deviceRelativeBaseUrl = | ||
(0, _getBaseUrlFromRequest.default)(req) ?? this.#serverBaseUrl; | ||
const oldDevice = this.#devices.get(deviceId); | ||
@@ -155,2 +157,3 @@ let newDevice; | ||
createMessageMiddleware: this.#customMessageHandler, | ||
deviceRelativeBaseUrl, | ||
serverRelativeBaseUrl: this.#serverBaseUrl, | ||
@@ -166,3 +169,3 @@ }; | ||
debug( | ||
`Got new connection: name=${deviceName}, app=${appName}, device=${deviceId}` | ||
`Got new connection: name=${deviceName}, app=${appName}, device=${deviceId}, via=${deviceRelativeBaseUrl.origin}` | ||
); | ||
@@ -169,0 +172,0 @@ socket.on("close", () => { |
{ | ||
"name": "@react-native/dev-middleware", | ||
"version": "0.77.0-nightly-20241120-a865975ce", | ||
"version": "0.77.0-nightly-20241121-550b0c0ed", | ||
"description": "Dev server middleware for React Native", | ||
@@ -26,3 +26,3 @@ "keywords": [ | ||
"@isaacs/ttlcache": "^1.4.1", | ||
"@react-native/debugger-frontend": "0.77.0-nightly-20241120-a865975ce", | ||
"@react-native/debugger-frontend": "0.77.0-nightly-20241121-550b0c0ed", | ||
"chrome-launcher": "^0.15.2", | ||
@@ -29,0 +29,0 @@ "chromium-edge-launcher": "^0.2.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102239
2313