Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mixdown-server

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mixdown-server - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

lib/couchconfig.js

1

index.js

@@ -8,3 +8,4 @@ var mixdown = {};

mixdown.MainFactory = require('./lib/main');
mixdown.CouchConfig = require('./lib/couchconfig.js');
module.exports = mixdown;

6

lib/app.js

@@ -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/"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc