forked from OSU-CS290-Sp18/final-project-group-22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
87 lines (72 loc) · 2.4 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var path = require('path');
var express = require('express');
var exphbs = require('express-handlebars');
var MongoClient = require('mongodb').MongoClient;
var app = express();
var mongoHost = process.env.MONGO_HOST;
var mongoPort = process.env.MONGO_PORT || '27017' ;
var mongoUsername = process.env.MONGO_USERNAME;
var mongoPassword = process.env.MONGO_PASSWORD;
var mongoDBName = process.env.MONGO_DB_NAME;
var mongoURL="mongodb://"+ mongoUsername+ ":"+ mongoPassword+ "@"+ mongoHost+ ":"+ mongoPort+ "/"+ mongoDBName;
var mongoDB =null;
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
var port = process.env.PORT || 3028;
app.get('/', function(req, res, next){
res.status(200).render('homePage');
});
app.get('/home', function(req, res, next){
res.status(200).render('homePage');
});
app.get('/joinus', function(req, res, next){
res.status(200).render('joinusPage');
});
app.get('/partnerships', function(req, res, next){
var companiesCollection=mongoDB.collection('companies');
companiesCollection.find().toArray(function (err, companies) {
if (err) {
res.status(500).send("Error fetching companies from DB.");
} else {
res.status(200).render('collabPage',{
company: companies
});
}
});
});
app.get('/blog', function(req, res, next){
var blogCollection=mongoDB.collection('blogContent');
var commentCollection=mongoDB.collection('comments');
blogCollection.find().toArray(function (err, blogContent) {
if(err){
res.status(500).send("Error fetching blog content from DB.");
}else{
commentCollection.find().toArray(function (err, comments) {
if (err) {
res.status(500).send("Error fetching blog comments from DB.");
} else {
res.status(200).render('blogPage',{
blogInfo: blogContent,
comment: comments
});
}
});
}
});
});
app.use(express.static('public'));
app.get('*', function (req, res) {
res.status(404).render('404Page');
});
/*app.listen(port, function () {
console.log("== Server is listening on port", port);
});*/
MongoClient.connect(mongoURL, function (err, client) {
if (err) {
throw err;
}
mongoDB = client.db(mongoDBName);
app.listen(port, function () {
console.log("== Server listening on port", port);
});
});