Skip to content

Commit

Permalink
Merge pull request Spacebrew#68 from Spacebrew/http
Browse files Browse the repository at this point in the history
serving admin interface from server
  • Loading branch information
quinkennedy committed Feb 29, 2016
2 parents 9da5211 + 2d24ecc commit 1b56f16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions node_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ var main = function() {
"port": defaultPort,
"logLevel": logger.debugLevel
}

// create spacebrew server
spacebrew.createServer( server_configs );
if (persist) persister.persistRoutes( persist_configs);
}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"author": "LAB at Rockwell Group",
"license": "MIT",
"dependencies": {
"ws": "~0.4.25",
"forever-monitor": "1.1.0"
"finalhandler": "^0.4.1",
"forever-monitor": "1.1.0",
"serve-static": "^1.10.2",
"ws": "~0.4.25"
}
}
32 changes: 23 additions & 9 deletions spacebrew.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var path = require('path')
, ws = require('ws')
, logger = require('./logger')
, spacebrew = exports
, serveStatic = require('serve-static')
, http = require('http')
, finalhandler = require('finalhandler')
;

//create a new WebsocketServer
Expand All @@ -25,6 +28,11 @@ spacebrew.createServer = function( opts ){
var expose = {};
opts = opts || {};
opts.port = opts.port || 9000;
/**
* host can be set to limit which network interfaces to listen on.
* The default is 0.0.0.0 which will listen on all interfaces.
* Setting 'localhost' will only listen on the loopback interface
*/
opts.host = opts.host || '0.0.0.0';
opts.ping = opts.ping || true;
opts.forceClose = opts.forceClose || false;
Expand All @@ -34,15 +42,21 @@ spacebrew.createServer = function( opts ){

logger.log("info", "[createServer] log level set to " + logger.debugLevel);

/**
* startup the websocket server.
* The port specifies which port to listen on
* The 'host = 0.0.0.0' specifies to listen to ALL incoming traffic,
* not just localhost or a specific IP
*/
// create basic static folder
var serve = serveStatic('admin');

var server = http.createServer(
function(req, res){
var done = finalhandler(req, res)
serve(req, res, done)
}
);

server.listen(opts.port, opts.host);

// allow websocket connections on the existing server.
var wss = new ws.Server({
port: opts.port,
host: opts.host
server: server
});

expose.wss = wss;
Expand Down Expand Up @@ -1009,4 +1023,4 @@ spacebrew.createServer = function( opts ){
}
return expose;

};
};

0 comments on commit 1b56f16

Please sign in to comment.