Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add HTTP request logger & App environement #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions config/db.js

This file was deleted.

6 changes: 6 additions & 0 deletions config/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var configs = {
"port": 8080,
"mongoDSN" : 'mongodb://<user>:<pass>@mongo.onmodulus.net:27017/uw45mypu'
};

module.exports = configs;
6 changes: 6 additions & 0 deletions config/prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var configs = {
"port": 80,
"mongoDSN" : 'mongodb://<user>:<pass>@mongo.onmodulus.net:27017/uw45mypu'
};

module.exports = configs;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

25 changes: 19 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
exports = module.exports = app; // expose app