2017-03-29 17:50:05 +00:00
|
|
|
let finalhandler = require('finalhandler');
|
|
|
|
let http = require('http');
|
|
|
|
let serveStatic = require('serve-static');
|
2016-08-21 15:02:50 +00:00
|
|
|
|
2017-03-29 17:50:05 +00:00
|
|
|
let Server = function(options) {
|
2016-08-21 15:02:50 +00:00
|
|
|
this.dist = options.dist || 'dist/';
|
|
|
|
this.port = options.port || 8000;
|
2016-10-30 01:41:50 +00:00
|
|
|
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) {
|
2017-03-29 17:50:05 +00:00
|
|
|
let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
|
2016-08-21 15:02:50 +00:00
|
|
|
|
2017-03-29 17:50:05 +00:00
|
|
|
let server = http.createServer(function onRequest (req, res) {
|
2016-08-21 15:02:50 +00:00
|
|
|
serve(req, res, finalhandler(req, res));
|
|
|
|
});
|
|
|
|
|
2017-02-16 01:56:18 +00:00
|
|
|
this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
|
2016-10-30 01:41:50 +00:00
|
|
|
server.listen(this.port, this.hostname) ;
|
2016-08-21 15:02:50 +00:00
|
|
|
callback();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Server;
|