From 0bbc789793cdafd2ca46e719cec10eb06b357764 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Mon, 4 May 2015 10:37:36 +0200 Subject: [PATCH 1/2] Add HTTP request logger & App environement --- config/db.js | 3 --- config/dev.js | 6 ++++++ config/prod.js | 6 ++++++ package.json | 10 +++++----- server.js | 25 +++++++++++++++++++------ 5 files changed, 36 insertions(+), 14 deletions(-) delete mode 100644 config/db.js create mode 100644 config/dev.js create mode 100644 config/prod.js diff --git a/config/db.js b/config/db.js deleted file mode 100644 index fcddeaf1..00000000 --- a/config/db.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - url : 'mongodb://:@mongo.onmodulus.net:27017/uw45mypu' -} \ No newline at end of file diff --git a/config/dev.js b/config/dev.js new file mode 100644 index 00000000..e6f55f11 --- /dev/null +++ b/config/dev.js @@ -0,0 +1,6 @@ +var configs = { + "port": 8000, + "mongoDSN" : 'mongodb://:@mongo.onmodulus.net:27017/uw45mypu' +}; + +module.exports = configs; diff --git a/config/prod.js b/config/prod.js new file mode 100644 index 00000000..c5814d15 --- /dev/null +++ b/config/prod.js @@ -0,0 +1,6 @@ +var configs = { + "port": 80, + "mongoDSN" : 'mongodb://:@mongo.onmodulus.net:27017/uw45mypu' +}; + +module.exports = configs; diff --git a/package.json b/package.json index 9fdb424f..48011977 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,10 @@ "name": "starter-node-angular", "main": "server.js", "dependencies": { - "express" : "~4.5.1", - "mongoose" : "~3.8.0", - "body-parser" : "~1.4.2", - "method-override" : "~2.0.2" + "body-parser": "~1.4.2", + "express": "~4.5.1", + "method-override": "~2.0.2", + "mongoose": "~3.8.0", + "morgan": "^1.5.2" } } - diff --git a/server.js b/server.js index b802c31a..b324f037 100644 --- a/server.js +++ b/server.js @@ -6,12 +6,25 @@ var bodyParser = require('body-parser'); var methodOverride = require('method-override'); // configuration =========================================== - -// config files -var db = require('./config/db'); -var port = process.env.PORT || 8080; // set our port -// mongoose.connect(db.url); // connect to our mongoDB database (commented out after you enter in your own credentials) +if(process.argv.indexOf("--prod") != "-1") +{ + var $env = "prod"; + console.log("Prod environment"); + var config = require("./config/prod.js"); +} +else +{ + var $env = "dev"; + console.log("Dev environment"); + var config = require("./config/dev.js"); +} + +// HTTP request logger +app.use(require('morgan')($env, {})); + +var port = process.env.PORT || config.port; +// mongoose.connect(config.mongoDSN); // connect to our mongoDB database (commented out after you enter in your own credentials) // get all data/stuff of the body (POST) parameters app.use(bodyParser.json()); // parse application/json @@ -27,4 +40,4 @@ require('./app/routes')(app); // pass our application into our routes // start app =============================================== app.listen(port); console.log('Magic happens on port ' + port); // shoutout to the user -exports = module.exports = app; // expose app \ No newline at end of file +exports = module.exports = app; // expose app From 7ab3d7f3e78263447faf5fb7e1214c8fa3fd75f1 Mon Sep 17 00:00:00 2001 From: Sauleau Sven Date: Mon, 4 May 2015 10:41:01 +0200 Subject: [PATCH 2/2] Update dev.js --- config/dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/dev.js b/config/dev.js index e6f55f11..5d0da88d 100644 --- a/config/dev.js +++ b/config/dev.js @@ -1,5 +1,5 @@ var configs = { - "port": 8000, + "port": 8080, "mongoDSN" : 'mongodb://:@mongo.onmodulus.net:27017/uw45mypu' };