Skip to content

Commit

Permalink
hacky "hey I already connected" approach to multi-browser support
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdustan committed Apr 3, 2015
1 parent 5ea6d13 commit f0d2d0d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packager/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,30 @@ function openStackFrameInEditor(req, res, next) {
}

function getDevToolsLauncher(options) {
var connected = false;
return function(req, res, next) {
if (req.url === '/debugger-ui') {
var debuggerPath = path.join(__dirname, 'debugger.html');
res.writeHead(200, {'Content-Type': 'text/html'});
fs.createReadStream(debuggerPath).pipe(res);
} else if (req.url === '/launch-browser-devtools') {
var debuggerURL = 'http://localhost:' + options.port + '/debugger-ui';
console.log('Launching Dev Tools in default browser...');
exec('open' + ' ' + debuggerURL, function(err, stdout, stderr) {
if (err) {
console.log('Failed to open ' + debuggerURL, err);
}
console.log(stdout);
console.warn(stderr);
});
res.end('OK');
if (connected) {
console.log('Already connect to Dev Tools in default browser...');
res.end('OK');
}
else {
var debuggerURL = 'http://localhost:' + options.port + '/debugger-ui';
console.log('Launching Dev Tools in default browser...');
connected = true;
exec('open' + ' ' + debuggerURL, function(err, stdout, stderr) {
if (err) {
console.log('Failed to open ' + debuggerURL, err);
}
console.log(stdout);
console.warn(stderr);
});
res.end('OK');
}
} else {
next();
}
Expand Down

0 comments on commit f0d2d0d

Please sign in to comment.