Tidy app.js

remotes/origin/bin-rhel65
Raul Ochoa 10 years ago
parent 2eb7529efb
commit 907ed478cf

@ -29,7 +29,7 @@ test: config/environments/test.js
jshint: jshint:
@echo "***jshint***" @echo "***jshint***"
@./node_modules/.bin/jshint lib/ @./node_modules/.bin/jshint lib/ app.js
test-all: jshint test test-all: jshint test

@ -7,17 +7,21 @@
* environments: [development, production] * environments: [development, production]
*/ */
var path = require('path'), var path = require('path');
fs = require('fs'), var fs = require('fs');
RedisPool = require('redis-mpool') var RedisPool = require('redis-mpool');
; var _ = require('underscore');
if ( process.argv[2] ) ENV = process.argv[2]; var ENV;
else if ( process.env['NODE_ENV'] ) ENV = process.env['NODE_ENV']; if ( process.argv[2] ) {
else ENV = 'development'; ENV = process.argv[2];
} else if ( process.env.NODE_ENV ) {
ENV = process.env.NODE_ENV;
} else {
ENV = 'development';
}
process.env['NODE_ENV'] = ENV; process.env.NODE_ENV = ENV;
// sanity check // sanity check
if (ENV != 'development' && ENV != 'production' && ENV != 'staging' ){ if (ENV != 'development' && ENV != 'production' && ENV != 'staging' ){
@ -26,14 +30,12 @@ if (ENV != 'development' && ENV != 'production' && ENV != 'staging' ){
process.exit(1); process.exit(1);
} }
var _ = require('underscore');
// set environment specific variables // set environment specific variables
global.environment = require(__dirname + '/config/environments/' + ENV); global.environment = require(__dirname + '/config/environments/' + ENV);
global.environment.api_hostname = require('os').hostname().split('.')[0]; global.environment.api_hostname = require('os').hostname().split('.')[0];
global.log4js = require('log4js'); global.log4js = require('log4js');
log4js_config = { var log4js_config = {
appenders: [], appenders: [],
replaceConsole:true replaceConsole:true
}; };
@ -60,18 +62,18 @@ if ( global.environment.log_filename ) {
); );
} }
log4js.configure(log4js_config, { cwd: __dirname }); global.log4js.configure(log4js_config, { cwd: __dirname });
global.logger = log4js.getLogger(); global.logger = global.log4js.getLogger();
var redisOpts = _.extend(global.environment.redis, { name: 'windshaft' }), var redisOpts = _.extend(global.environment.redis, { name: 'windshaft' }),
redisPool = new RedisPool(redisOpts); redisPool = new RedisPool(redisOpts);
// Include cartodb_windshaft only _after_ the "global" variable is set // Include cartodb_windshaft only _after_ the "global" variable is set
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28 // See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
var CartodbWindshaft = require('./lib/cartodb/cartodb_windshaft'), var cartodbWindshaft = require('./lib/cartodb/cartodb_windshaft'),
serverOptions = require('./lib/cartodb/server_options')(redisPool); serverOptions = require('./lib/cartodb/server_options')(redisPool);
ws = CartodbWindshaft(serverOptions); var ws = cartodbWindshaft(serverOptions);
if (global.statsClient) { if (global.statsClient) {
redisPool.on('status', function(status) { redisPool.on('status', function(status) {
@ -93,19 +95,20 @@ ws.listen(global.environment.port, global.environment.host);
var version = require("./package").version; var version = require("./package").version;
ws.on('listening', function() { ws.on('listening', function() {
console.log("Windshaft tileserver " + version + " started on " console.log(
+ global.environment.host + ':' + global.environment.port "Windshaft tileserver %s started on %s:%s (%s)",
+ " (" + ENV + ")"); version, global.environment.host, global.environment.port, ENV
);
}); });
process.on('SIGHUP', function() { process.on('SIGHUP', function() {
global.log4js.clearAndShutdownAppenders(function() { global.log4js.clearAndShutdownAppenders(function() {
global.log4js.configure(log4js_config); global.log4js.configure(log4js_config);
global.logger = log4js.getLogger(); global.logger = global.log4js.getLogger();
console.log('Log files reloaded'); console.log('Log files reloaded');
}); });
}); });
process.on('uncaughtException', function(err) { process.on('uncaughtException', function(err) {
logger.error('Uncaught exception: ' + err.stack); global.logger.error('Uncaught exception: ' + err.stack);
}); });

Loading…
Cancel
Save