embark-area-51/lib/server.js

25 lines
752 B
JavaScript
Raw Normal View History

2016-08-21 15:02:50 +00:00
var finalhandler = require('finalhandler');
var http = require('http');
var serveStatic = require('serve-static');
var Server = function(options) {
this.dist = options.dist || 'dist/';
this.port = options.port || 8000;
this.hostname = options.host || 'localhost';
2016-09-17 03:56:25 +00:00
this.logger = options.logger;
2016-08-21 15:02:50 +00:00
};
Server.prototype.start = function(callback) {
var serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
var server = http.createServer(function onRequest (req, res) {
serve(req, res, finalhandler(req, res));
});
this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
server.listen(this.port, this.hostname) ;
2016-08-21 15:02:50 +00:00
callback();
};
module.exports = Server;