-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
68 lines (53 loc) · 1.75 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
// server.js
// init project
// the following const defining order cannot be changed
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const session = require('express-session');
const passport = require('passport');
const flash = require('connect-flash');
const { connectDB } = require('./DBconnect');
const moment = require('moment');
const app = express();
// Connect to the DB
connectDB();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.locals.moment = moment;
// Load passport related session
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: { secure: 'auto' }
}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
// Middleware to setup flash messages, need to check again on this part
// app.use((req, res, next) => {
// res.locals.success_msg = req.flash('success_msg');
// res.locals.error_msg = req.flash('error_msg');
// res.locals.error = req.flash('error');
// next();
// });
// Set the view engine
app.set("view engine", "ejs")
app.set("views", __dirname + "/views/");
// Load routes
const staticRouter = require("./routes/static");
const userRouter = require("./routes/user");
const projectRouter = require("./routes/project");
const apiRouter = require("./routes/api");
const adminRouter = require("./routes/admin");
app.use("/", staticRouter);
app.use("/", userRouter);
app.use("/", projectRouter);
app.use("/api", apiRouter);
app.use("/admin", adminRouter);
// listen for requests :)
const listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});