Browse Source

removed console log
- used port normalization function

camalot 8 years ago
parent
commit
c04cf5d84b
1 changed files with 17 additions and 2 deletions
  1. 17 2
      bin/www

+ 17 - 2
bin/www

@@ -9,7 +9,6 @@ var fs = require('fs');
 var envFile = path.join(__dirname, '../.env');
 try {
   fs.accessSync(envFile, fs.F_OK);
-  console.log("loading .env file");
   require('dotenv').config({path: envFile});
 } catch (e) {
   // no env file
@@ -19,11 +18,27 @@ var app = require('../app');
 var debug = require('debug')('slack-invite-automation:server');
 var http = require('http');
 
+/**
+ * Normalize a port into a number, string, or false.
+ * @param {int} val
+ */
+function normalizePort(val) {
+    var port = parseInt(val, 10);
+    if (isNaN(port)) {
+        return val;
+    } else if (port >= 0) {
+        return port;
+    }
+
+    return false;
+}
+
+
 /**
  * Get port from environment and store in Express.
  */
 
-var port = parseInt(process.env.PORT, 10) || 3000;
+var port = normalizePort(process.env.PORT || '3000');
 app.set('port', port);
 
 /**