Skip to content

Commit

Permalink
Added REPL socket, so server can be connected to and refreshed withou…
Browse files Browse the repository at this point in the history
…t restarting.
  • Loading branch information
jefftrudeau committed Apr 18, 2011
1 parent b61cc0c commit 563c367
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/project/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ this.option = {
log: {
truncate: false,
logs: [archetype_project_root+'/%PROJECT%.log']
},

repl: {
host: '127.0.0.1',
port: 8193
}

};
25 changes: 21 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/

var http = require('http'),
net = require('net'),
repl = require('repl'),
common = require('./common'),
database = require('./database').database,
log = require('./log').log,
Expand All @@ -21,6 +23,8 @@ this.server = {

_http: null,

_repl: null,

dispatch: function (request, response) {
try {
request.__url = common.url.parse(request.url);
Expand Down Expand Up @@ -55,6 +59,7 @@ this.server = {

refresh: function () {
try {
console.log('Refreshing server ...');
database.init();
route.init();
service.init();
Expand All @@ -68,10 +73,22 @@ this.server = {
start: function () {
self._http = http.createServer(function (request, response) {
self.dispatch(request, response);
});
self._http.listen(option.http.port, option.http.host);
console.log('http://' + option.http.host + ':' + option.http.port + '/');
//TODO receive input from command-line and execute commands accordingly
}).listen(option.http.port, option.http.host);

self._repl = net.createServer(function (socket) {
repl.start('archetype>', socket).context.server = self;
}).listen(option.repl.port);

self.status();
},

status: function () {
var msg =
'This instance of archetype is operational and listening for active connections:\n' +
' (HTTP) http://' + option.http.host + ':' + option.http.port + '/\n' +
' (REPL) tcp://' + option.repl.host + ':' + option.repl.port + '/';
log.debug(msg);
console.log(msg);
}

};
Expand Down

0 comments on commit 563c367

Please sign in to comment.