| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 98e9ab8 commit 25670cb
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | #!/usr/bin/env node | |
| 2 | 2 | ||
| 3 | - var dserver = require('../lib/debug-server'), | ||
| 3 | + var DebugServer = require('../lib/debug-server').DebugServer, | ||
| 4 | 4 | fs = require('fs'), | |
| 5 | 5 | path = require('path'), | |
| 6 | 6 | options = {}; | |
@@ -12,7 +12,6 @@ process.argv.forEach(function (arg) { | |||
| 12 | 12 | if (parts.length > 1) { | |
| 13 | 13 | switch (parts[0]) { | |
| 14 | 14 | case '--web-port': | |
| 15 | - case '--agent-port': | ||
| 16 | 15 | options.webPort = parseInt(parts[1], 10); | |
| 17 | 16 | break; | |
| 18 | 17 | default: | |
@@ -21,7 +20,7 @@ process.argv.forEach(function (arg) { | |||
| 21 | 20 | } | |
| 22 | 21 | } | |
| 23 | 22 | else if (parts[0] === '--help') { | |
| 24 | - console.log('Usage: node [node_options] debug-agent.js [options]'); | ||
| 23 | + console.log('Usage: node-inspector [options]'); | ||
| 25 | 24 | console.log('Options:'); | |
| 26 | 25 | console.log('--web-port=[port] port to host the inspector (default 8080)'); | |
| 27 | 26 | process.exit(); | |
@@ -30,7 +29,8 @@ process.argv.forEach(function (arg) { | |||
| 30 | 29 | }); | |
| 31 | 30 | ||
| 32 | 31 | fs.readFile(path.join(__dirname, '../config.json'), function(err, data) { | |
| 33 | - var config; | ||
| 32 | + var config, | ||
| 33 | + dserver; | ||
| 34 | 34 | if (err) { | |
| 35 | 35 | console.warn("could not load config.json\n" + err.toString()); | |
| 36 | 36 | config = {}; | |
@@ -49,8 +49,11 @@ fs.readFile(path.join(__dirname, '../config.json'), function(err, data) { | |||
| 49 | 49 | if (!config.debugPort) { | |
| 50 | 50 | config.debugPort = 5858; | |
| 51 | 51 | } | |
| 52 | - dserver.create(options, config).on('close', function () { | ||
| 52 | + | ||
| 53 | + dserver = new DebugServer(); | ||
| 54 | + dserver.on('close', function () { | ||
| 53 | 55 | console.log('session closed'); | |
| 54 | 56 | process.exit(); | |
| 55 | 57 | }); | |
| 58 | + dserver.listen(options.webPort || config.webPort); | ||
| 56 | 59 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,65 +1,63 @@ | |||
| 1 | 1 | var Http = require('http'), | |
| 2 | 2 | EventEmitter = require('events').EventEmitter, | |
| 3 | - path = require('path'), | ||
| 4 | 3 | WebSocket = require('websocket-server'), | |
| 5 | 4 | paperboy = require('paperboy'), | |
| 6 | 5 | Session = require('./session'), | |
| 7 | - WEBROOT = path.join(__dirname, '../front-end'), | ||
| 8 | - sessions = {}; | ||
| 6 | + inherits = require('util').inherits, | ||
| 7 | + WEBROOT = require('path').join(__dirname, '../front-end'), | ||
| 8 | + sessions = {}, | ||
| 9 | + webPort; | ||
| 9 | 10 | ||
| 10 | - function staticFile(req, res) { | ||
| 11 | + function serveStaticFiles(req, res) { | ||
| 11 | 12 | req.url = req.url.replace(/^\/debug/, '/'); | |
| 12 | 13 | paperboy.deliver(WEBROOT, req, res); | |
| 13 | 14 | } | |
| 14 | 15 | ||
| 15 | - function override(options, defaults) { | ||
| 16 | - var result = {}; | ||
| 17 | - Object.keys(defaults).forEach(function(key) { | ||
| 18 | - result[key] = options[key] || defaults[key]; | ||
| 19 | - }); | ||
| 20 | - return result; | ||
| 16 | + function getDebuggerPort(url, defaultPort) { | ||
| 17 | + return parseInt((/\?port=(\d+)/.exec(url) || [null, defaultPort])[1], 10); | ||
| 21 | 18 | } | |
| 22 | 19 | ||
| 23 | - exports.create = function(options, config) { | ||
| 24 | - var defaults = { webPort: config.webPort }, | ||
| 25 | - settings = override(options || {}, defaults), | ||
| 26 | - httpServer = Http.createServer(staticFile), | ||
| 27 | - wsServer = WebSocket.createServer({server: httpServer}), | ||
| 28 | - debugPort = config.debugPort.toString(); | ||
| 20 | + function getSession(debuggerPort) { | ||
| 21 | + var session = sessions[debuggerPort]; | ||
| 22 | + if (!session) { | ||
| 23 | + session = Session.create(debuggerPort, {}); // TODO fix config | ||
| 24 | + sessions[debuggerPort] = session; | ||
| 25 | + // TODO session on close | ||
| 26 | + } | ||
| 27 | + return session; | ||
| 28 | + } | ||
| 29 | 29 | ||
| 30 | - wsServer.on('connection', function(conn) { | ||
| 31 | - var port = | ||
| 32 | - parseInt((/\?port=(\d+)/.exec(conn._req.url) || [null, debugPort])[1], 10), | ||
| 33 | - session = sessions[port]; | ||
| 34 | - if (!session) { | ||
| 35 | - session = Session.create(port, config); | ||
| 36 | - sessions[port] = session; | ||
| 37 | - } | ||
| 38 | - session.join(conn) | ||
| 39 | - // XXX should session and debugger be bound together? | ||
| 40 | - }); | ||
| 30 | + function handleWebSocketConnection(conn) { | ||
| 31 | + var port = getDebuggerPort(conn._req.url, 5858); // TODO | ||
| 32 | + getSession(port).join(conn) | ||
| 33 | + } | ||
| 41 | 34 | ||
| 42 | - wsServer.listen(settings.webPort); | ||
| 35 | + function handleServerListening() { | ||
| 36 | + console.log( | ||
| 37 | + 'visit http://0.0.0.0:' + | ||
| 38 | + webPort + | ||
| 39 | + '/debug?port=5858 to start debugging'); // TODO port | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + function DebugServer() { | ||
| 43 | + var httpServer = Http.createServer(serveStaticFiles); | ||
| 44 | + this.wsServer = WebSocket.createServer({ server: httpServer }); | ||
| 45 | + this.wsServer.on('connection', handleWebSocketConnection); | ||
| 46 | + this.wsServer.on('listening', handleServerListening); | ||
| 47 | + } | ||
| 43 | 48 | ||
| 44 | - wsServer.on('listening', function() { | ||
| 45 | - console.log( | ||
| 46 | - 'visit http://0.0.0.0:' + | ||
| 47 | - settings.webPort + | ||
| 48 | - '/debug?port=5858 to start debugging'); | ||
| 49 | - }); | ||
| 49 | + inherits(DebugServer, EventEmitter); | ||
| 50 | + | ||
| 51 | + DebugServer.prototype.close = function() { | ||
| 52 | + if (this.wsServer) { | ||
| 53 | + this.wsServer.close(); | ||
| 54 | + this.emit('close'); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + DebugServer.prototype.listen = function(port) { | ||
| 59 | + webPort = port; | ||
| 60 | + this.wsServer.listen(port); | ||
| 61 | + } | ||
| 50 | 62 | ||
| 51 | - return Object.create(EventEmitter.prototype, { | ||
| 52 | - close: { | ||
| 53 | - value: function() | ||
| 54 | - { | ||
| 55 | - if (wsServer) { | ||
| 56 | - wsServer.close(); | ||
| 57 | - } | ||
| 58 | - this.emit('close'); | ||
| 59 | - } | ||
| 60 | - }, | ||
| 61 | - webPort: { | ||
| 62 | - get: function() { return settings.webPort; } | ||
| 63 | - } | ||
| 64 | - }); | ||
| 65 | - }; | ||
| 63 | + exports.DebugServer = DebugServer; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,5 @@ | |||
| 1 | - var http = require('http'), | ||
| 2 | - events = require('events'), | ||
| 3 | - debugr = require('./debugger'), | ||
| 4 | - path = require('path'); | ||
| 1 | + var events = require('events'), | ||
| 2 | + debugr = require('./debugger'); | ||
| 5 | 3 | ||
| 6 | 4 | /////////////////////////////////////////////////////////// | |
| 7 | 5 | // exports | |
| Back | FazBrowse Home | New Git URL |
0 commit comments