Permalink
Browse files

Remove config package; migrate to environment variables

  • Loading branch information...
lovett committed Jun 8, 2014
1 parent 4c0a6a1 commit d3c725d0d55c084c3b7a3a42cd77c78c1efab8dc
Showing with 33 additions and 31 deletions.
  1. +1 −1 config/default.json
  2. +6 −1 env.json.sample
  3. +0 −1 package.json
  4. +1 −22 server/index.js
  5. +25 −6 world.js
@@ -4,5 +4,5 @@
},
"logPath": "headlines.log",
"logLevel": "trace",
"feedCheckIntervalMinutes": 10
"feedCheckIntervalMinutes": 60
}
@@ -1,4 +1,9 @@
{
"HEADLINES_LIVERELOAD": 35730,
"HEADLINES_DEV_HOST": "localhost"
"HEADLINES_DEV_HOST": "localhost",
"HEADLINES_HTTP_IP": "0.0.0.0",
"HEADLINES_HTTP_PORT": 8081,
"HEADLINES_LOG": "headlines.log",
"HEADLINES_LOG_LEVEL": "trace",
"HEADLINES_FEED_CHECK_INTERVAL_MINUTES": 60
}
@@ -32,7 +32,6 @@
"dependencies": {
"bunyan": "0.23.1",
"cityhash": "0.0.5",
"config": "0.4.36",
"elasticsearch": "2.2.0",
"htmlparser": "1.7.7",
"htmlparser2": "3.7.2",
@@ -4,27 +4,6 @@ var server = restify.createServer();
var elasticsearch = require('elasticsearch');
var logger = world.logger.child({source: 'webserver'});

/**
* Environment variables
* --------------------------------------------------------------------
*
* If the file env.json exists, declare its contents as environtment
* variables.
*/
var env;
try {
env = world.fs.readFileSync('env.json', {encoding: 'utf8'});
env = JSON.parse(env);

Object.keys(env).forEach(function (key) {
process.env[key] = env[key];
});
} catch (e) {
}

env = {};


/**
* Standard middleware
* --------------------------------------------------------------------
@@ -477,7 +456,7 @@ server.get('/.*', restify.serveStatic({
* Listening begins
* --------------------------------------------------------------------
*/
server.listen(world.config.http.port, function() {
server.listen(process.env.HEADLINES_HTTP_PORT, process.env.HEADLINES_HTTP_IP, function() {
logger.info({address: server.url}, 'startup');
});

@@ -1,9 +1,28 @@
var config = require('config');
var redis = require('redis');
var bunyan = require('bunyan');
var fs = require('fs');

/**
* Environment variables
* --------------------------------------------------------------------
*
* If the file env.json exists, declare its contents as environtment
* variables.
*/
var env;
try {
env = fs.readFileSync('env.json', {encoding: 'utf8'});
env = JSON.parse(env);

Object.keys(env).forEach(function (key) {
process.env[key] = env[key];
});
} catch (e) {
}

env = {};

module.exports = {
config: config,
events: require('events'),
client: redis.createClient(),
redisClient: redis.createClient(),
@@ -26,12 +45,12 @@ module.exports = {
},
streams: [
{
path: config.logPath,
level: config.logLevel
path: process.env.HEADLINES_LOG,
level: process.env.HEADLINES_LOG_LEVEL
}
]
}),
fs: require('fs'),
fs: fs,
mkdirp: require('mkdirp'),
path: require('path'),
archivePath: function (hash) {
@@ -43,7 +62,7 @@ module.exports = {
minToMs: function (min) {
return min * 60 * 1000;
},
feedCheckInterval: Math.max(10, config.feedCheckIntervalMinutes) * 60 * 1000,
feedCheckInterval: Math.max(10, process.env.HEADLINES_FEED_CHECK_INTERVAL_MINUTES) * 60 * 1000,
keys: {
// A sorted set of how many users are subscribed to each feed
// The set memeber is a feed id. The score is the number of

0 comments on commit d3c725d

Please sign in to comment.