Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added REPL socket, so server can be connected to and refreshed withou…

…t restarting.
  • Loading branch information...
commit 563c3672398569a611cd0fc5b120fbd442fd9b6a 1 parent b61cc0c
@jefftrudeau authored
Showing with 26 additions and 4 deletions.
  1. +5 −0 lib/project/option.js
  2. +21 −4 lib/server.js
View
5 lib/project/option.js
@@ -30,6 +30,11 @@ this.option = {
log: {
truncate: false,
logs: [archetype_project_root+'/%PROJECT%.log']
+ },
+
+ repl: {
+ host: '127.0.0.1',
+ port: 8193
}
};
View
25 lib/server.js
@@ -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,
@@ -21,6 +23,8 @@ this.server = {
_http: null,
+ _repl: null,
+
dispatch: function (request, response) {
try {
request.__url = common.url.parse(request.url);
@@ -55,6 +59,7 @@ this.server = {
refresh: function () {
try {
+ console.log('Refreshing server ...');
database.init();
route.init();
service.init();
@@ -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);
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.