refactor server

This commit is contained in:
Iuri Matias 2016-08-21 11:02:50 -04:00
parent 6f5c5fae36
commit eb95ae7fd6
2 changed files with 49 additions and 36 deletions

View File

@ -32,6 +32,33 @@ var Embark = {
return this.contractsManager;
},
run: function(env) {
Embark.deploy(function(abi) {
Embark.buildAssets(abi);
var server = new Server();
server.start(function() {
Embark.watch();
});
});
},
build: function(env) {
Embark.deploy(function(abi) {
Embark.buildAssets(abi);
});
},
blockchain: function(env, client) {
var blockchain = Blockchain(client);
blockchain.run({env: env});
},
deploy: function(done) {
async.waterfall([
function loadConfig(callback) {
@ -90,22 +117,6 @@ var Embark = {
},
server: function(callback) {
var finalhandler = require('finalhandler');
var http = require('http');
var serveStatic = require('serve-static');
// Serve up public/ftp folder
var serve = serveStatic('dist/', {'index': ['index.html', 'index.htm']});
// Create server
var server = http.createServer(function onRequest (req, res) {
serve(req, res, finalhandler(req, res));
});
// Listen
console.log("listening on port 8000".underline.green);
server.listen(8000) ;
callback();
},
watch: function() {
@ -131,26 +142,6 @@ var Embark = {
.on('unlink', path => console.log(`File ${path} has been removed`))
.on('ready', () => console.log('ready to watch changes'));
console.log("done!");
},
run: function(env) {
Embark.deploy(function(abi) {
Embark.buildAssets(abi);
Embark.server(function() {
Embark.watch();
});
});
},
build: function(env) {
Embark.deploy(function(abi) {
Embark.buildAssets(abi);
});
},
blockchain: function(env, client) {
var blockchain = Blockchain(client);
blockchain.run({env: env});
}
};

22
lib/server.js Normal file
View File

@ -0,0 +1,22 @@
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;
};
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));
});
console.log(("listening on port " + this.port).underline.green);
server.listen(this.port) ;
callback();
};
module.exports = Server;