convert app to use node-config

This commit is contained in:
Erik Kristensen 2014-03-18 09:19:21 -04:00
parent 2deda5b68a
commit ebb814a39a
4 changed files with 75 additions and 6 deletions

36
config/default.js Normal file
View File

@ -0,0 +1,36 @@
module.exports = {
host: process.env.HOST || 'localhost',
port: process.env.PORT || 7777,
keyLength: 10,
maxLength: 400000,
staticMaxAge: 86400,
recompressStaticAssets: true,
logging: [
{
level: "verbose",
type: "Console",
colorize: true
}
],
keyGenerator: {
type: "phonetic"
},
storage: {
type: "redis",
host: process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT || 6379,
db: process.env.REDIS_DB || 2,
expire: process.env.REDIS_EXPIRE || 2592000
},
documents: {
about: "./about.md"
}
};

36
config/docker.js Normal file
View File

@ -0,0 +1,36 @@
module.exports = {
host: "0.0.0.0",
port: 7777,
keyLength: 10,
maxLength: 400000,
staticMaxAge: 86400,
recompressStaticAssets: true,
logging: [
{
level: "verbose",
type: "Console",
colorize: true
}
],
keyGenerator: {
type: "phonetic"
},
storage: {
type: "redis",
host: process.env.REDIS_PORT_6379_TCP_ADDR || process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT_6379_TCP_PORT || process.env.REDIS_PORT || 6379,
db: process.env.REDIS_DB || 2,
expire: process.env.REDIS_EXPIRE || 2592000
},
documents: {
about: "./about.md"
}
};

View File

@ -18,7 +18,8 @@
"connect": "1.9.2",
"redis-url": "0.1.0",
"redis": "0.8.1",
"uglify-js": "1.3.3"
"uglify-js": "1.3.3",
"config": "0.4.35"
},
"devDependencies": {
"mocha": "*",

View File

@ -1,17 +1,13 @@
var http = require('http');
var url = require('url');
var fs = require('fs');
var config = require('config');
var winston = require('winston');
var connect = require('connect');
var DocumentHandler = require('./lib/document_handler');
// Load the configuration and set some defaults
var config = JSON.parse(fs.readFileSync('./config.js', 'utf8'));
config.port = process.env.PORT || config.port || 7777;
config.host = process.env.HOST || config.host || 'localhost';
// Set up the logger
if (config.logging) {
try {