Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serving admin interface from server #68

Merged
merged 3 commits into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

};
};