Skip to content

Commit

Permalink
Add client side new config
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Apr 21, 2015
1 parent 83e8298 commit 66e0601
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ WORKDIR /usr/src/democracyos/app
# If you change the port, remember to set the proper ENV var to match.
EXPOSE 80

CMD node ./bin/dos-config && node index.js
CMD node index.js
27 changes: 0 additions & 27 deletions bin/dos-config

This file was deleted.

58 changes: 31 additions & 27 deletions config/defaults.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,63 @@
{
"locale" : "en",
"protocol": "http",
"host": "localhost",
"privatePort": 3000,
"publicPort": 3000,
"privatePort": 3000,
"mongoUrl": "mongodb://localhost/DemocracyOS-dev",
"mongoUsersUrl": "",
"secret": "Generate a secret token and paste it here.",
"deploymentId": "",
"deploymentDomain": "",
"corsDomains": "",
"signinUrl": "",
"signupUrl": "",
"settingsUrl": "",
"staff": [],
"auth": {
"basic": {
"username": "",
"password": ""
}
},
"ssl": {
"serverKey": "server.key",
"serverCert": "server.crt",
"port": 443,
"redirect": "normal"
},
"notifications": {
"url": "http://localhost:9001/api/events",
"token": 1234
},
"client": [
"protocol",
"host",
"publicPort",
"env",
"locale",
"logo",
"logoMobile",
"favicon",
"organizationName",
"organizationUrl",
"learnMoreUrl",
"googleAnalyticsTrackingId",
"commentsPerPage",
"faq",
"tos",
"pp",
"tos",
"glossary",
"signinUrl",
"signupUrl",
"settingsUrl",
"clientDebug",
"homeLink",
"logoMobile",
"usersWhitelist",
"deploymentDomain",
"headerBackgroundColor",
"headerFontColor"
],
"auth": {
"basic": {
"username": "",
"password": ""
}
},
"socialshare" : {
"siteName" : "DemocracyOS",
"siteDescription" : "DemocracyOS voting system",
Expand All @@ -49,16 +67,12 @@
"username" : "@democracyos"
}
},
"locale" : "en",
"logo": "/lib/boot/images/logo.png",
"logoMobile": "/lib/boot/images/logo.png",
"favicon" : " /lib/boot/images/favicon.ico",
"organizationName" : "DemocracyOS on GitHub",
"organizationUrl" : "https://github.com/DemocracyOS/app",
"learnMoreUrl": "http://www.democracyos.org",
"headerBackgroundColor": "",
"headerFontColor": "",
"staff": [],
"googleAnalyticsTrackingId" : "",
"rssEnabled" : true,
"commentsPerPage": 0,
Expand All @@ -67,20 +81,10 @@
"tos": false,
"pp": false,
"glossary": false,
"notifications": {
"url": "http://localhost:9001/api/events",
"token": 1234
},
"secret": "Just a sample secret string",
"ssl": {
"serverKey": "server.key",
"serverCert": "server.crt",
"port": 443,
"redirect": "normal"
},
"clientDebug": "",
"googleAPIKey": "",
"homeLink": "/",
"clientDebug": "",
"usersWhitelist": false,
"deploymentDomain": "localhost"
"headerBackgroundColor": "",
"headerFontColor": "",
"googleAPIKey": ""
}
12 changes: 12 additions & 0 deletions lib/config/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var config = require('lib/config');
var client = {};

config.client.forEach(function(key){
if (!config.hasOwnProperty(key)) {
throw new Error('Config key "' + key + '" non existent.');
}

client[key] = config[key];
});

module.exports = client;
8 changes: 8 additions & 0 deletions lib/config/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "config",
"description": "Client config component",
"dependencies": {},
"locals": [],
"scripts": [ "config.js" ],
"main": "config.js"
}
1 change: 1 addition & 0 deletions lib/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = window.config;
13 changes: 11 additions & 2 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var log = require('debug')('democracyos:config');
var resolve = require('path').resolve;
var path = require('path');
var fs = require('fs');
var typeOf = require('component-type');
var changeCase = require('change-case');
var cast = require('./cast-string');
Expand Down Expand Up @@ -60,7 +61,7 @@ function parse(val, key, scope){
}

var local = get(localConfig, s);
if (local.hasOwnProperty(key)) {
if (local && local.hasOwnProperty(key)) {
var newVal = local[key];
if (typeOf(val) !== typeOf(newVal)) {
throw new Error('Invalid value for key "' + key + '" on "' + environment + '.json": ' + '". Should be "' + typeOf(val) + '".');
Expand All @@ -73,7 +74,7 @@ function parse(val, key, scope){

function get(obj, scope) {
var c = obj;
if (scope) scope.forEach(function(k){ c = c[k] });
if (scope) scope.forEach(function(k){ c = c ? c[k] : null; });
return c;
}

Expand All @@ -87,4 +88,12 @@ function forEach(obj, cb) {
});
}

config.env = environment;

if (!config.secret || config.secret === defaultConfig.secret) {
var crypto = require('crypto');
var token = crypto.randomBytes(32).toString('hex');
throw new Error('Must set a unique token for your app on the "secret" key of the configuration.\n\nHere\'s one just for you: "' + token + '".\n');
}

module.exports = config;
10 changes: 4 additions & 6 deletions lib/debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ var debug = require('debug');
* Initialize debug
*/

if (config.clientDebug && true === config.clientDebug) {
debug.disable();
debug.disable();

if (config.clientDebug === '*') {
debug.enable('democracyos:*');
} else if (config.clientDebug && 'string' === typeof config.clientDebug) {
debug.disable();
} else if (config.clientDebug) {
debug.enable(config.clientDebug);
} else {
debug.disable();
}

module.exports = debug;
4 changes: 2 additions & 2 deletions lib/law-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ app.post('/law/:id/publish', restrict, staff, function (req, res) {
instance: instanceUrl
};

if (config('deployment id')) {
data.deploymentId = config('deployment id');
if (config.deploymentId) {
data.deploymentId = config.deploymentId;
}

notifier.notify(eventName)
Expand Down
9 changes: 2 additions & 7 deletions lib/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
*/

var config = require('lib/config');
var clientConfig = require('lib/config/client');
var path = require('path');
var resolve = path.resolve;
var html = resolve(__dirname, 'index.jade');

module.exports = function (req, res) {
var client = {};

config.client.forEach(function(k) {
client[k] = config[k];
});

res.render(html, { config: config, client: client });
res.render(html, { config: config, client: clientConfig });
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@
"node": "0.10.x"
},
"scripts": {
"postinstall": "node ./bin/dos-install && node ./bin/dos-config && node ./bin/dos-build"
"postinstall": "node ./bin/dos-install && node ./bin/dos-build"
}
}

0 comments on commit 66e0601

Please sign in to comment.