From 907ed478cff21ddb0d8ac83987e129d24b2b94f1 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Tue, 7 Apr 2015 13:00:20 +0200 Subject: [PATCH] Tidy app.js --- Makefile | 2 +- app.js | 45 ++++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 11899d75..2bd19912 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ test: config/environments/test.js jshint: @echo "***jshint***" - @./node_modules/.bin/jshint lib/ + @./node_modules/.bin/jshint lib/ app.js test-all: jshint test diff --git a/app.js b/app.js index 539043e9..19361566 100755 --- a/app.js +++ b/app.js @@ -7,17 +7,21 @@ * environments: [development, production] */ -var path = require('path'), - fs = require('fs'), - RedisPool = require('redis-mpool') -; +var path = require('path'); +var fs = require('fs'); +var RedisPool = require('redis-mpool'); +var _ = require('underscore'); +var ENV; +if ( process.argv[2] ) { + ENV = process.argv[2]; +} else if ( process.env.NODE_ENV ) { + ENV = process.env.NODE_ENV; +} else { + ENV = 'development'; +} -if ( process.argv[2] ) 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 if (ENV != 'development' && ENV != 'production' && ENV != 'staging' ){ @@ -26,14 +30,12 @@ if (ENV != 'development' && ENV != 'production' && ENV != 'staging' ){ process.exit(1); } -var _ = require('underscore'); - // set environment specific variables global.environment = require(__dirname + '/config/environments/' + ENV); global.environment.api_hostname = require('os').hostname().split('.')[0]; global.log4js = require('log4js'); -log4js_config = { +var log4js_config = { appenders: [], replaceConsole:true }; @@ -60,18 +62,18 @@ if ( global.environment.log_filename ) { ); } -log4js.configure(log4js_config, { cwd: __dirname }); -global.logger = log4js.getLogger(); +global.log4js.configure(log4js_config, { cwd: __dirname }); +global.logger = global.log4js.getLogger(); var redisOpts = _.extend(global.environment.redis, { name: 'windshaft' }), redisPool = new RedisPool(redisOpts); // Include cartodb_windshaft only _after_ the "global" variable is set // 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); -ws = CartodbWindshaft(serverOptions); +var ws = cartodbWindshaft(serverOptions); if (global.statsClient) { redisPool.on('status', function(status) { @@ -93,19 +95,20 @@ ws.listen(global.environment.port, global.environment.host); var version = require("./package").version; ws.on('listening', function() { - console.log("Windshaft tileserver " + version + " started on " - + global.environment.host + ':' + global.environment.port - + " (" + ENV + ")"); + console.log( + "Windshaft tileserver %s started on %s:%s (%s)", + version, global.environment.host, global.environment.port, ENV + ); }); process.on('SIGHUP', function() { global.log4js.clearAndShutdownAppenders(function() { global.log4js.configure(log4js_config); - global.logger = log4js.getLogger(); + global.logger = global.log4js.getLogger(); console.log('Log files reloaded'); }); }); process.on('uncaughtException', function(err) { - logger.error('Uncaught exception: ' + err.stack); + global.logger.error('Uncaught exception: ' + err.stack); });