Skip to content

Commit

Permalink
Prevents JS Debugger issues with CORS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Nico authored and facebook-github-bot committed Jan 27, 2018
1 parent 8aa568e commit 29f8354
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions local-cli/server/middleware/getDevToolsMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const launchChrome = require('../util/launchChrome');

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

function launchChromeDevTools(port, args = '') {
var debuggerURL = 'http://localhost:' + port + '/debugger-ui' + args;
function launchChromeDevTools(host, args = '') {
var debuggerURL = 'http://' + host + '/debugger-ui' + args;
console.log('Launching Dev Tools...');
launchChrome(debuggerURL);
}
Expand All @@ -25,7 +25,7 @@ function escapePath(pathname) {
return '"' + pathname + '"';
}

function launchDevTools({port, projectRoots}, isChromeConnected) {
function launchDevTools({host, projectRoots}, isChromeConnected) {
// Explicit config always wins
var customDebugger = process.env.REACT_DEBUGGER;
if (customDebugger) {
Expand All @@ -39,12 +39,13 @@ function launchDevTools({port, projectRoots}, isChromeConnected) {
});
} else if (!isChromeConnected()) {
// Dev tools are not yet open; we need to open a session
launchChromeDevTools(port);
launchChromeDevTools(host);
}
}

module.exports = function(options, isChromeConnected) {
return function(req, res, next) {
var host = req.headers.host;
if (req.url === '/launch-safari-devtools') {
// TODO: remove `console.log` and dev tools binary
console.log(
Expand All @@ -62,7 +63,7 @@ module.exports = function(options, isChromeConnected) {
launchDevTools(options, isChromeConnected);
res.end('OK');
} else if (req.url === '/launch-js-devtools') {
launchDevTools(options, isChromeConnected);
launchDevTools({...options, host}, isChromeConnected);
res.end('OK');
} else {
next();
Expand Down

0 comments on commit 29f8354

Please sign in to comment.