From 3c2599f29b5cac4c132445019298d44806b56c33 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Thu, 25 Jun 2015 17:21:19 +0200 Subject: [PATCH] Removed log for deploy (optimize space on the cloud) --- lib/controllers.js | 7 +++++-- lib/posts.js | 6 ++++-- server.js | 15 ++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/controllers.js b/lib/controllers.js index d9b0642..7345012 100644 --- a/lib/controllers.js +++ b/lib/controllers.js @@ -7,6 +7,9 @@ var fs = require('fs'); module.exports = function(parent, options){ var verbose = options.verbose; + + verbose && console.log("Loading controllers :"); + fs.readdirSync(__dirname + '/../controllers').forEach(function(name){ // index.js in controller, with function as pages (views.py for django) @@ -27,9 +30,9 @@ module.exports = function(parent, options){ verbose && console.log('\t' + name + ':'); for (var key in urls) { app.get(key, obj[urls[key]]); - console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]); + verbose && console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]); } - console.log(); + verbose && console.log(); // mount the app parent.use(app); diff --git a/lib/posts.js b/lib/posts.js index 5fd9d1e..d6a1825 100644 --- a/lib/posts.js +++ b/lib/posts.js @@ -8,6 +8,8 @@ var fs = require('fs'); module.exports = function(parent, options){ var verbose = options.verbose; + verbose && console.log("Loading controllers :"); + fs.readdirSync(__dirname + '/../posts').forEach(function(name){ // index.js in controller, with function as pages (views.py for django) @@ -28,9 +30,9 @@ module.exports = function(parent, options){ verbose && console.log('\t' + name + ':'); for (var key in urls) { app.post(key, obj[urls[key]]); - console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]); + verbose && console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]); } - console.log(); + verbose && console.log(); // mount the app parent.use(app); diff --git a/server.js b/server.js index eef29f7..41e37b5 100644 --- a/server.js +++ b/server.js @@ -18,6 +18,8 @@ var session = require('cookie-session'); var cookieParser = require('cookie-parser'); var urls = require('./urls'); +var isDev = app.get('env') === 'development'; + app.set('view engine', 'jade'); app.set('trust proxy', 1); @@ -55,12 +57,10 @@ app.use(function(req, res, next) { // }); // Load controllers -console.log("Loading controllers :"); -require('./lib/controllers')(app, { verbose: !module.parent }); +require('./lib/controllers')(app, { verbose: isDev }); // Load post to log data from user study -console.log("Loading posts :"); -require('./lib/posts')(app, { verbose: !module.parent }); +require('./lib/posts')(app, { verbose: isDev }); // Static files app.use('/static', express.static('static')); @@ -87,7 +87,7 @@ app.use(function(req, res) { // Set ports and ip address var server_port, server_ip_address; -if ( app.get('env') === 'development' ) { +if ( isDev ) { server_port = 4000; server_ip_address = 'localhost'; } else { @@ -97,6 +97,7 @@ if ( app.get('env') === 'development' ) { } // Start server -http.listen(server_port, server_ip_address, function(){ - console.log("Server ready : now listening " + server_ip_address + ":" + server_port); +http.listen(server_port, server_ip_address, function() { + if (isDev) + console.log("Server ready : now listening " + server_ip_address + ":" + server_port); });