Skip to content

Commit 29f8354

Browse files
Nicofacebook-github-bot
Nico
authored andcommitted
Prevents JS Debugger issues with CORS
Summary: <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> See #17618 On certain networks, `xip.io` is used, but as the debugger will always using localhost a change upstream has resulted in a CORS issue (see screenshots in #17618). This change ensures that the debugger will always open with whatever configuration. > This should be merged in as a patch of `0.52.x` as it affects current release, and `0.51.x` didn't have this issue. Tested locally, could do with the people having the same issue in #17618 testing it out prior to merging. (If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.) <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [CLI] [BUGFIX] [local-cli/server/middleware/getDevToolsMiddleware.js] - Prevents JS Debugger issues with CORS Closes #17720 Differential Revision: D6828205 Pulled By: hramos fbshipit-source-id: 7e5d43db9faf7edc9444ba4214aca1a18e25dbd2
1 parent 8aa568e commit 29f8354

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

local-cli/server/middleware/getDevToolsMiddleware.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const launchChrome = require('../util/launchChrome');
1414

1515
const {exec} = require('child_process');
1616

17-
function launchChromeDevTools(port, args = '') {
18-
var debuggerURL = 'http://localhost:' + port + '/debugger-ui' + args;
17+
function launchChromeDevTools(host, args = '') {
18+
var debuggerURL = 'http://' + host + '/debugger-ui' + args;
1919
console.log('Launching Dev Tools...');
2020
launchChrome(debuggerURL);
2121
}
@@ -25,7 +25,7 @@ function escapePath(pathname) {
2525
return '"' + pathname + '"';
2626
}
2727

28-
function launchDevTools({port, projectRoots}, isChromeConnected) {
28+
function launchDevTools({host, projectRoots}, isChromeConnected) {
2929
// Explicit config always wins
3030
var customDebugger = process.env.REACT_DEBUGGER;
3131
if (customDebugger) {
@@ -39,12 +39,13 @@ function launchDevTools({port, projectRoots}, isChromeConnected) {
3939
});
4040
} else if (!isChromeConnected()) {
4141
// Dev tools are not yet open; we need to open a session
42-
launchChromeDevTools(port);
42+
launchChromeDevTools(host);
4343
}
4444
}
4545

4646
module.exports = function(options, isChromeConnected) {
4747
return function(req, res, next) {
48+
var host = req.headers.host;
4849
if (req.url === '/launch-safari-devtools') {
4950
// TODO: remove `console.log` and dev tools binary
5051
console.log(
@@ -62,7 +63,7 @@ module.exports = function(options, isChromeConnected) {
6263
launchDevTools(options, isChromeConnected);
6364
res.end('OK');
6465
} else if (req.url === '/launch-js-devtools') {
65-
launchDevTools(options, isChromeConnected);
66+
launchDevTools({...options, host}, isChromeConnected);
6667
res.end('OK');
6768
} else {
6869
next();

0 commit comments

Comments
 (0)