Created
November 27, 2016 11:50
-
-
Save sidorares/0ca51dc65049e51da854b3456980dcf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const parse = require('url').parse; | |
const spawn = require('child_process').spawn; | |
const script = ` | |
(function() { | |
document.addEventListener('mousedown', function(e) { | |
var dom = e.target; | |
for (var key in dom) { | |
if (key.startsWith("__reactInternalInstance$")) { | |
var compInternals = dom[key]._currentElement; | |
var source = compInternals._source; | |
console.log(source) | |
fetch('http://localhost:8040/source?filename=' + source.fileName + '&line=' + source.lineNumber); | |
} | |
} | |
}); | |
})(); | |
` | |
http.createServer((req, res) => { | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Request-Method', '*'); | |
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); | |
res.setHeader('Access-Control-Allow-Headers', '*'); | |
if ( req.method === 'OPTIONS' ) { | |
res.writeHead(200); | |
res.end(); | |
return; | |
} | |
if (req.url.startsWith('/atom.js')) { | |
res.end(script); | |
} else if (req.url.startsWith('/source')) { | |
const q = parse(req.url, true).query; | |
console.log(q); | |
res.end('ok'); | |
spawn('atom', [`${q.filename}:${q.line}`]); | |
} else { | |
res.writeHead(404); | |
res.end(); | |
} | |
}).listen(8040); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment