add server config

This commit is contained in:
oleg 2015-05-18 21:25:08 +03:00
parent 7b2fe328a7
commit bf97e2c7c5
4 changed files with 43 additions and 13 deletions

46
app.js
View File

@ -4,7 +4,10 @@ var http = require('http'),
nodeStatic = require('node-static'), nodeStatic = require('node-static'),
jade = require('jade'), jade = require('jade'),
path = require('path'), path = require('path'),
fs = require('fs'); fs = require('fs'),
Steppy = require('twostep').Steppy,
_ = require('underscore'),
reader = require('./lib/reader');
var staticServer = new nodeStatic.Server('./static'); var staticServer = new nodeStatic.Server('./static');
var server = http.createServer(function(req, res, next) { var server = http.createServer(function(req, res, next) {
@ -29,17 +32,38 @@ var app = {
dataio: dataio dataio: dataio
}; };
app.config = {};
app.config.paths = {};
// path to root dir (with projects, builds etc) Steppy(
app.config.paths.data = path.join(process.cwd(), 'data'); function() {
app.config.paths.projects = path.join(app.config.paths.data, 'projects'); app.config = {};
app.config.paths.builds = path.join(app.config.paths.data, 'builds'); app.config.paths = {};
fs.exists(app.config.paths.builds, function(exists) {
if (!exists) fs.mkdir(app.config.paths.builds);
});
require('./resources')(app); // path to root dir (with projects, builds etc)
app.config.paths.data = path.join(process.cwd(), 'data');
app.config.paths.projects = path.join(app.config.paths.data, 'projects');
app.config.paths.builds = path.join(app.config.paths.data, 'builds');
var stepCallback = this.slot();
fs.exists(app.config.paths.builds, function(isExists) {
stepCallback(null, isExists);
});
reader.load(app.config.paths.data, 'config', this.slot());
},
function(err, isBuildsDirExists, config) {
if (!isBuildsDirExists) {
fs.mkdir(app.config.paths.builds, this.slot());
}
_(app.config).defaults(config);
console.log('Server config:', JSON.stringify(app.config.nodes, null, 4));
require('./resources')(app);
},
function(err) {
if (err) throw err;
}
);
app.server.listen(3000); app.server.listen(3000);

6
data/config.json Normal file
View File

@ -0,0 +1,6 @@
{
"nodes": [{
"type": "local",
"maxExecutorsCount": 1
}]
}

View File

@ -30,7 +30,7 @@ gulp.task('develop', function() {
return nodemon({ return nodemon({
ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'], ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'],
script: 'app.js', script: 'app.js',
ext: 'js' ext: 'js,json'
}); });
}); });

View File

@ -27,7 +27,7 @@ module.exports = function(app) {
}); });
var distributor = new Distributor({ var distributor = new Distributor({
nodes: [{type: 'local', maxExecutorsCount: 1}], nodes: app.config.nodes,
saveBuild: function(build, callback) { saveBuild: function(build, callback) {
Steppy( Steppy(
function() { function() {