diff options
| author | Kumar Damani <damani.kumar@gmail.com> | 2019-02-19 20:29:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-19 20:29:42 +0000 |
| commit | 3449364d8a922faf7187c6870876a92aacde5556 (patch) | |
| tree | 86d1123889ac79e8e0a6448ed78022201c331f68 /web/routes | |
| parent | df5d61aae6c2a94f1619496dc4d204b22e81b7ce (diff) | |
| parent | 58d54b74424e1213c1888f3c3925ab8578d092f3 (diff) | |
Merge pull request #9 from csc301-winter-2019/feat/4
Feat/4
Diffstat (limited to 'web/routes')
| -rw-r--r-- | web/routes/index.js | 61 | ||||
| -rw-r--r-- | web/routes/users.js | 9 |
2 files changed, 70 insertions, 0 deletions
diff --git a/web/routes/index.js b/web/routes/index.js new file mode 100644 index 0000000..ffe1c21 --- /dev/null +++ b/web/routes/index.js @@ -0,0 +1,61 @@ +var express = require('express'); +var router = express.Router(); + +// Mongoose import +var mongoose = require('mongoose'); + +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}`); + } +}); + +// Mongoose Schema definition +var Schema = mongoose.Schema; +var JsonSchema = new Schema({ + name: String, + type: Schema.Types.Mixed, + coordinates: Array +}); + +// Mongoose Model definition +var Json = mongoose.model('Jstring', JsonSchema, 'pointscollection'); + +/* GET home page. */ +router.get('/', function(req, res, next) { + // for now just redirect to /map + //res.render('index', { title: 'Welcome' }); + res.redirect('/map'); +}); + +/* GET Map page. */ +router.get('/map', function(req,res) { + // we can use the database to fetch a point, SELECT coordinates + Json.findOne({name: "points"}, 'coordinates', function(e,point){ + if (e) return e; + // send the view lat, and long. + res.render('map', { + lat : point.coordinates[1], + lng : point.coordinates[0] + }); + }); +}); + +module.exports = router; diff --git a/web/routes/users.js b/web/routes/users.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/web/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.send('respond with a resource'); +}); + +module.exports = router; |
