-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (56 loc) · 1.85 KB
/
app.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
const express = require('express');
const bodyparser = require('body-parser');
// const mongoose = require('mongoose');
const app = express();
const mongoose = require("./database");
const middleware = require('./middleware')
const path = require('path');
const session = require("express-session");
// var _ = require('lodash');
app.set("view engine", "ejs");
app.set("views", "views");
app.use(bodyparser.urlencoded({
extended: false
}));
app.use(express.static("public"));
app.use(session({
secret: "bbq chips",
resave: true,
saveUninitialized: false
}))
// routes
const loginRoute = require('./routes/loginRoutes');
app.use('/login', loginRoute);
const registerRoute = require('./routes/registerRoutes');
app.use('/register', registerRoute);
const logoutRoute = require('./routes/logout');
app.use('/logout', logoutRoute);
// api post routes
const postsApiRoute = require('./routes/api/posts');
app.use('/api/posts', postsApiRoute);
const userApiRoute = require('./routes/api/users');
app.use('/api/users', userApiRoute);
const postRoute = require('./routes/viewPost');
app.use('/posts', middleware.requireLogin, postRoute);
const profileRoute = require('./routes/profilePage');
app.use('/profile', middleware.requireLogin, profileRoute);
const searchRoute = require('./routes/searchRoutes');
app.use('/search', middleware.requireLogin, searchRoute);
const discussRoute = require('./routes/discussRoutes');
app.use('/discussion', middleware.requireLogin, discussRoute);
app.get('/', middleware.requireLogin, (req, res, next) => {
var payload = {
pageTitle: "Home",
userLoggedIn: req.session.user,
profileUser : req.session.user,
userLoggedInJs : JSON.stringify(req.session.user)
}
res.status(200).render('home', {
payload: payload
});
})
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port);