From 29f8354c1946a6325e9020b9ef5ee4ccdf0fa51f Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 27 Jan 2018 02:21:49 -0800 Subject: [PATCH] Prevents JS Debugger issues with CORS Summary: 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.) [CLI] [BUGFIX] [local-cli/server/middleware/getDevToolsMiddleware.js] - Prevents JS Debugger issues with CORS Closes https://github.com/facebook/react-native/pull/17720 Differential Revision: D6828205 Pulled By: hramos fbshipit-source-id: 7e5d43db9faf7edc9444ba4214aca1a18e25dbd2 --- local-cli/server/middleware/getDevToolsMiddleware.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/local-cli/server/middleware/getDevToolsMiddleware.js b/local-cli/server/middleware/getDevToolsMiddleware.js index 4f90d2853..e6621ac57 100644 --- a/local-cli/server/middleware/getDevToolsMiddleware.js +++ b/local-cli/server/middleware/getDevToolsMiddleware.js @@ -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); } @@ -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) { @@ -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( @@ -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();