mixdown-server
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -17,4 +17,3 @@ var util = require('util'), | ||
App.prototype.init = function(first_argument) { | ||
App.prototype.init = function() { | ||
var plugins = this.plugins, | ||
@@ -21,0 +20,0 @@ app = this; |
@@ -10,13 +10,13 @@ var util = require('util'), | ||
* Config - loads and manages configuration for environment and sites. | ||
* options: { | ||
* configManager: the configuration manager for this app (this is injected to support unit testing separate from app instantiation) | ||
* sitepath: path to the site folder | ||
* } | ||
* @param config - Object containing the server configuration. | ||
**/ | ||
var Config = function() {}; | ||
var Config = function(config) { | ||
this.config = config; | ||
}; | ||
util.inherits(Config, events.EventEmitter); | ||
Config.prototype.init = function(raw) { | ||
var that = this; | ||
Config.prototype.init = function() { | ||
var that = this, | ||
raw = this.config; | ||
@@ -42,2 +42,31 @@ this.server = raw.server; | ||
/** | ||
* Applies the overrides from the env config. Useful for setting a base config, then applying configuration overrides. | ||
* @param env - String representing the env overrides for this config. This will load the config | ||
**/ | ||
Config.prototype.env = function(env) { | ||
if (env) { | ||
// apply merge of plugins at app level | ||
_.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; }); | ||
if (esite) { | ||
// apply overrides of plugins | ||
_.bind(mergeSection, site, esite, 'plugins', true)(); | ||
// apply overrides of hostmap | ||
site.hostmap = esite.hostmap; | ||
} | ||
}); | ||
// apply server overrides. things like port number | ||
_.extend(this.config.server, env.server); | ||
} | ||
}; | ||
// create local utility function to apply the merge. | ||
@@ -44,0 +73,0 @@ var mergeSection = function(parent, section, reverse) { |
{ | ||
"name": "mixdown-server", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "index", | ||
@@ -5,0 +5,0 @@ "description": "Simple server for activiting a site.", |
var mixdown = require('../index'), | ||
serverConfig = new mixdown.Config(); | ||
serverConfig = new mixdown.Config(require("./server.json")); | ||
@@ -8,5 +8,6 @@ serverConfig.on('error', function(err) { | ||
}); | ||
debugger; | ||
serverConfig.init(require("./server.json")); | ||
serverConfig.env(require("./server-override.json")); | ||
serverConfig.init(); | ||
// start server. Sets up server, port, and starts the app. | ||
@@ -13,0 +14,0 @@ var server = new mixdown.Server(serverConfig); |
@@ -25,7 +25,7 @@ var Router = require('pipeline-router'); | ||
if (err) { | ||
res.writeHead(500, { 'Content-Type': 'text/plain' }); | ||
res.writeHead(500, app.plugins.headers({ 'Content-Type': 'text/plain' })); | ||
res.end(err + err.stack); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/html' }); | ||
res.writeHead(200, app.plugins.headers({ 'Content-Type': 'text/html' })); | ||
res.end(html); | ||
@@ -43,7 +43,7 @@ } | ||
if (err) { | ||
res.writeHead(500, { 'Content-Type': 'text/plain' }); | ||
res.writeHead(500, app.plugins.headers({ 'Content-Type': 'text/plain' })); | ||
res.end(err + err.stack); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/html' }); | ||
res.writeHead(200, app.plugins.headers({ 'Content-Type': 'text/html' })); | ||
res.end(html); | ||
@@ -50,0 +50,0 @@ } |
@@ -15,2 +15,8 @@ { | ||
"options": {} | ||
}, | ||
"headers": { | ||
"module": "/tests/headers.js", | ||
"options": { | ||
"headers": { "mixdown-test": "base config" } | ||
} | ||
} | ||
@@ -23,3 +29,3 @@ } | ||
"hostmap": [ | ||
"mixdown.local", | ||
"localhost", | ||
"127.0.0.1" | ||
@@ -26,0 +32,0 @@ ], |
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
11283
17
355