-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (68 loc) · 2.2 KB
/
index.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
const dotenv = require('dotenv');
const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes/routes.js');
const mongoose = require('mongoose');
const hbs = require('hbs');
const db = require('./models/db.js');
const session = require('express-session');
const MongoStore = require('connect-mongodb-session')(session);
const Comment = require('./models/CommentModel.js');
const app = express();
hbs.registerHelper('eq', function(arg1, arg2) {
return (arg1 == arg2);
});
hbs.registerHelper('inArray', function(element, array) {
if (array.includes(element))
return true;
else
return false;
});
hbs.registerHelper('getNestedCommentCount', async function (parentid) {
var comments = await db.findMany(Comment, {parentid: parentid});
return 0;
});
hbs.registerHelper('usernamelink', function (username, current) {
if (username == current) {
return true;
}
else {
return false;
}
});
dotenv.config();
port = process.env.PORT;
hostname = process.env.HOSTNAME;
app.set('view engine', 'hbs');
hbs.registerPartials(__dirname + './views/partials');
app.use(express.static('public'));
app.use(bodyParser.urlencoded( {extended: false} ));
app.use(bodyParser.json());
const mongoStore = new MongoStore({
uri: 'mongodb+srv://noahhbernardo:[email protected]/hive',
collectionName: 'sessions',
});
const maxAgeInMilliseconds = 60 * 60 * 1000; // 1 hour
app.use(
session({
secret: 'secret_key',
resave: false,
saveUninitialized: true,
cookie: {
maxAge: maxAgeInMilliseconds,
},
store: mongoStore,
})
);
app.use(`/`, routes);
db.connect();
//Use this for online database (submission)
app.listen(port, function() {
console.log('Server running at port: ' + port);
console.log('Access website through: https://hive-f2w2.onrender.com');
});
//Use this for local database (Testing and debugging)
// app.listen(port, hostname, function() {
// console.log('Server running at: ');
// console.log('http://' + hostname + ':' + port);
// });