aboutsummaryrefslogtreecommitdiff
path: root/web/app.js
diff options
context:
space:
mode:
authorivanshen <iwshen11@gmail.com>2019-03-05 04:12:16 +0000
committerivanshen <iwshen11@gmail.com>2019-03-05 04:12:16 +0000
commit786d0aacd27f27875568c7a89d9e1df918fadbf3 (patch)
treee313a040f1a44d8a3f7cfb51736f295b94d76df6 /web/app.js
parentc16d2af861f4ed452b2b43f087290f5c0889c34d (diff)
parent18cfcf14ea982d3277d819b88b0dd4df96da40d0 (diff)
Merge branch 'qa' of github.com:csc301-winter-2019/project-team-02 into qa
Diffstat (limited to 'web/app.js')
-rw-r--r--web/app.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/web/app.js b/web/app.js
index ab7aed4..f0ae3a5 100644
--- a/web/app.js
+++ b/web/app.js
@@ -3,6 +3,7 @@ var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
+var mongoose = require('mongoose');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
@@ -19,6 +20,29 @@ app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
+var env = process.env.NODE_ENV || 'development';
+var uri;
+if (env === 'development') {
+ uri = 'mongodb://localhost:27017/helpthehome'
+ // use for small testing only if really necessary
+ // uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true'
+} else if (env === 'qa') {
+ uri = process.env.MONGODB_URI
+} else if (env === 'production') {
+ uri = ''
+}
+
+// Mongoose connection to MongoDB
+mongoose.connect(uri, { useNewUrlParser: true }, function (error) {
+ if (error) {
+ console.log(error);
+ console.log("App was not able to connect to the mongo server!");
+ console.log("... double check that the mongo server is running locally");
+ } else {
+ console.log(`connected to ${uri}`);
+ }
+});
+
app.use('/', indexRouter);
app.use('/users', usersRouter);