mixdown-server
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -8,3 +8,4 @@ var mixdown = {}; | ||
mixdown.MainFactory = require('./lib/main'); | ||
mixdown.CouchConfig = require('./lib/couchconfig.js'); | ||
module.exports = mixdown; |
@@ -17,6 +17,6 @@ var util = require('util'), | ||
App.prototype.init = function() { | ||
App.prototype.init = function(callback) { | ||
var plugins = this.plugins, | ||
app = this; | ||
_.each(this.config.plugins, function(p) { | ||
@@ -65,2 +65,4 @@ var Mod = null, | ||
}); | ||
_.isFunction(callback) ? callback() : null; | ||
}; | ||
@@ -67,0 +69,0 @@ |
var util = require('util'), | ||
events = require('events'), | ||
fs = require('fs'), | ||
App = require('./app'), | ||
_ = require('lodash'); | ||
async = require('async'), | ||
broadway = require('broadway'), | ||
App = require('./app.js'), | ||
_ = require('lodash'), | ||
pluginUtil = require('./pluginutil.js'); | ||
@@ -14,2 +17,4 @@ /** | ||
this.config = config; | ||
this._originalconfig = _.clone(config); | ||
this._externalConfig = null; | ||
}; | ||
@@ -19,11 +24,34 @@ | ||
Config.prototype.init = function() { | ||
var that = this, | ||
raw = this.config; | ||
Config.prototype.init = function(callback) { | ||
this.server = this.config.server; | ||
this.server = raw.server; | ||
this.apps = {}; | ||
var that = this; | ||
this.getExternalConfig(function(err, extConfig) { | ||
if (err) { | ||
_.isFunction(callback) ? callback(err) : null; | ||
return; | ||
} | ||
extConfig.getSites(function(err, sites) { | ||
if (err) { | ||
_.isFunction(callback) ? callback(err) : null; | ||
} | ||
that.updateSites(sites); | ||
that.initApps(callback); | ||
}); | ||
}); | ||
}; | ||
Config.prototype.initApps = function(callback) { | ||
var apps = {}; | ||
var inits = []; | ||
var raw = this.config; | ||
var that = this; | ||
// enumerate and create the apps | ||
_.each(raw.sites, function(site) { | ||
_.bind(mergeSection, site, raw.app, 'plugins')(); | ||
@@ -38,9 +66,125 @@ site.server = raw.server; | ||
app.id = site.id; | ||
app.init(); | ||
that.apps[site.id] = app; | ||
apps[site.id] = app; | ||
// enqueue the app init so we can attach a cb to the entire thing. | ||
inits.push(_.bind(app.init, app)); | ||
}); | ||
// async the inits and notify when they are done. | ||
// TODO: see if a single app failure could cause all apps to fail. | ||
async.parallel(inits, function(err) { | ||
if (!err) { | ||
that.apps = apps; | ||
} | ||
_.isFunction(callback) ? callback(err, that) : null; | ||
}); | ||
} | ||
Config.prototype.getExternalConfig = function(callback) { | ||
if (this.server.externalConfig && this._externalConfig) { | ||
_.isFunction(callback) ? callback(null, this._externalConfig) : null; | ||
return; | ||
} | ||
else if (!this.server.externalConfig) { | ||
_.isFunction(callback) ? callback() : null; | ||
return; | ||
} | ||
// new bw to attach dist config module. | ||
var app = new broadway.App(); | ||
var that = this; | ||
// resolve and attach dist config module. | ||
pluginUtil.use({ | ||
plugin: this.server.externalConfig, | ||
app: app | ||
}); | ||
app.externalConfig.once('sites', function(sites) { | ||
that.updateSites(sites); | ||
that.initApps(); | ||
}); | ||
// initialize dist config module | ||
app.init(function(err) { | ||
if (!err) { | ||
that._externalConfig = app.externalConfig; | ||
} | ||
_.isFunction(callback) ? callback(err, that._externalConfig) : null; | ||
}); | ||
}; | ||
/** | ||
* Applies the overrides for all sites with changes. Useful for updating 1 or more sites out of band, then applying configuration overrides. | ||
* @param sites - Array of site overrides for this config. | ||
**/ | ||
Config.prototype.updateSites = function(sites) { | ||
debugger; | ||
// generate a hash of all of the keys | ||
var keys = {}; | ||
var that = this; | ||
var newSitesArray = []; | ||
_.each(this._originalconfig.sites, function(s) { | ||
keys[s.id] = true; | ||
}); | ||
_.each(sites, function(s) { | ||
keys[s.id] = true; | ||
}); | ||
_.each(this.config.sites, function(s) { | ||
keys[s.id] = true; | ||
}); | ||
_.each(keys, function(junk, key) { | ||
var origConfig = _.find(that._originalconfig.sites, function(s) { return s.id == key; }); | ||
var overrideConfig = _.find(sites, function(s) { return s.id == key; }); | ||
var newConfig = null; | ||
// we have an original config from file and we have a override config, then merge them. | ||
if (origConfig && overrideConfig) { | ||
newConfig = _.clone(origConfig); | ||
// apply overrides of plugins | ||
_.bind(mergeSection, newConfig, overrideConfig, 'plugins', true)(); | ||
// apply overrides of hostmap | ||
newConfig.hostmap = overrideConfig.hostmap; | ||
} | ||
// there is only an override config, then use it. | ||
else if (overrideConfig) { | ||
newConfig = _.clone(overrideConfig); | ||
} | ||
// there is only an original config from file. | ||
else if (origConfig) { | ||
newConfig = _.clone(origConfig); | ||
} | ||
// there is no original file based config and the updated site is not in the override array. | ||
// This happens when a site is loaded from external config initially, then a single other site is being | ||
// updated that is not this one. | ||
// Ex: site A & B are both loaded from ext config. Then site B is updated from ext config. Site B is the only | ||
// item in the sites array in this function, but that does not mean that we want site A to stop working. | ||
else { | ||
newConfig = _.find(that.config.sites, function(s) { return s.id == key; }); | ||
} | ||
if (newConfig) { | ||
// replace the active site in the array | ||
newSitesArray.push(newConfig); | ||
} | ||
}); | ||
// swap the active site array | ||
this.config.sites = newSitesArray; | ||
} | ||
/** | ||
@@ -55,16 +199,13 @@ * Applies the overrides from the env config. Useful for setting a base config, then applying configuration overrides. | ||
// apply merge of plugins at app level | ||
_.bind(mergeSection, this.config.app, env.app, 'plugins', true)(); | ||
if (env.app) { | ||
_.bind(mergeSection, this.config.app, env.app, 'plugins', true)(); | ||
} | ||
_.each(this.config.sites, function(site) { | ||
var esite = _.find(env.sites, function(s) { return s.id == site.id; }); | ||
// apply env config to sites. | ||
this.updateSites(); | ||
if (esite) { | ||
// apply overrides of plugins | ||
_.bind(mergeSection, site, esite, 'plugins', true)(); | ||
// since this is an env override, then it should be applied and held as the original config so that | ||
// updates from dist config can be applied to the original config, not the prev version of config. | ||
this._originalconfig = this.config; | ||
// apply overrides of hostmap | ||
site.hostmap = esite.hostmap; | ||
} | ||
}); | ||
// apply server overrides. things like port number | ||
@@ -71,0 +212,0 @@ _.extend(this.config.server, env.server); |
@@ -55,2 +55,15 @@ var _ = require('lodash'), | ||
serverConfig.on('reload', function(serverCfg) { | ||
var hmap = []; | ||
_.each(serverConfig.apps, function(app) { | ||
hmap.push({ | ||
hostmap: app.config.hostmap, | ||
id: app.config.id | ||
}); | ||
}); | ||
logger.info("Server started successfully listening on " + util.inspect(that.socket.address()) + ". " + util.inspect(hmap) ); | ||
}); | ||
var createServer = function(done) { | ||
@@ -57,0 +70,0 @@ // start server. Sets up server, port, and starts the app. |
@@ -49,2 +49,30 @@ var _ = require('lodash'), | ||
// check if the external Config is enabled and starting listening if so. | ||
var that = this; | ||
serverConfig.getExternalConfig(function(err, externalConfig) { | ||
if (err) { | ||
logger.error(err); | ||
} | ||
else if (externalConfig) { | ||
externalConfig.on('sites', function(sites) { | ||
serverConfig.updateSites(sites); | ||
serverConfig.initApps(function(err) { | ||
if (err) { | ||
logger.error('Site refresh failed: ', err); | ||
} | ||
else { | ||
that.reload(); | ||
serverConfig.emit('reload', serverConfig); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
// create the server. | ||
@@ -61,3 +89,3 @@ this.start = function(callback) { | ||
var host = req.headers.host.replace(/:\d+/, ''), | ||
app = vhosts[host]; | ||
app = vhosts[host]; | ||
@@ -64,0 +92,0 @@ if (app) { |
{ | ||
"name": "mixdown-server", | ||
"version": "0.4.0", | ||
"main": "index", | ||
"description": "Simple server for activiting a site.", | ||
"keywords": [ | ||
"node", | ||
"server", | ||
"html" | ||
], | ||
"author": { | ||
"name": "Vast", | ||
"email": "vastjs-dev@vast.com", | ||
"web": "http://vastdevblog.vast.com/" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:mixdown/server" | ||
}, | ||
"directories": { | ||
"tests": "tests" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "node tests/main.js" | ||
}, | ||
"dependencies": { | ||
"lodash": "1.2.1", | ||
"broadway": "0.2.6", | ||
"optimist": "0.3.4", | ||
"winston": "0.6.2", | ||
"winston-syslog": "git+https://github.com/vast-eng/winston-syslog.git" | ||
}, | ||
"devDependencies": { | ||
"pipeline-router": "*", | ||
"broadway-handlebars": "*", | ||
"tap": "*" | ||
}, | ||
"optionalDependencies": {}, | ||
"homepage": "http://vastdevblog.vast.com/" | ||
"name": "mixdown-server", | ||
"version": "0.5.0", | ||
"main": "index", | ||
"description": "Simple server for activiting a site.", | ||
"keywords": [ | ||
"node", | ||
"server", | ||
"html" | ||
], | ||
"author": { | ||
"name": "Vast", | ||
"email": "vastjs-dev@vast.com", | ||
"web": "http://vastdevblog.vast.com/" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:mixdown/server" | ||
}, | ||
"directories": { | ||
"tests": "tests" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "node tests/main.js" | ||
}, | ||
"dependencies": { | ||
"lodash": "1.2.1", | ||
"broadway": "0.2.6", | ||
"async": "~0.2.5", | ||
"optimist": "0.3.4", | ||
"winston": "0.6.2", | ||
"cradle": "0.6.x", | ||
"winston-syslog": "git+https://github.com/vast-eng/winston-syslog.git" | ||
}, | ||
"devDependencies": { | ||
"pipeline-router": "*", | ||
"broadway-handlebars": "*", | ||
"tap": "*" | ||
}, | ||
"optionalDependencies": {}, | ||
"homepage": "http://vastdevblog.vast.com/" | ||
} | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32746
26
1031
7
9
+ Addedasync@~0.2.5
+ Addedcradle@0.6.x
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasync@0.2.10(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbrowser-request@0.3.3(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcradle@0.6.9(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@0.7.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfollow@0.11.4(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvargs@0.1.0(transitive)
+ Addedverror@1.10.0(transitive)