-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
69 lines (58 loc) · 2 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
const express = require("express");
const mongoose = require("mongoose");
const passport = require("passport");
const cookieSession = require("cookie-session");
const bodyParser = require("body-parser");
const expressValidator = require("express-validator");
const flash = require("connect-flash");
const authRoutes = require("./routes/auth-routes");
const meetingRoutes = require("./routes/meeting-routes");
const profileRoutes = require("./routes/profile-routes");
const connectRoutes = require("./routes/connect-routes");
const commentRoutes = require("./routes/comment-routes");
const app = express();
// load environment variables
if (process.env.NODE_ENV !== "production") require("dotenv").config();
const PORT = process.env.PORT;
const dbURI = process.env.MONGODB_URI;
const sessionSecret = process.env.SESSION;
const passportSetup = require("./config/passport-setup");
// set up view engine
app.set("view engine", "ejs");
app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000, // 1 day
keys: [sessionSecret]
}))
//initialize passport
app.use(passport.initialize());
app.use(passport.session());
// Use bluebird to avoid warning:
// "Mongoose: mpromise (mongoose's default promise library) is deprecated"
mongoose.Promise = require('bluebird');
// connect to mongodb using `mongoose.connect`...
var promise = mongoose.connect(dbURI, {
useMongoClient: true,
/* other options */
});
// use middleware
app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(expressValidator()); // Add this after the bodyParser middleware
app.use(flash());
// set up routes
app.use("/auth", authRoutes);
app.use("/meetings", meetingRoutes);
app.use("/profile", profileRoutes);
app.use("/connect", connectRoutes);
app.use("/comment", commentRoutes);
// create home route
app.get("/", (req, res) => {
res.render("index", {title: "GeckoMeet - Homepage", user: req.user});
});
// start the server
app.listen(PORT, (err) => {
if (err) {
throw err;
}
console.log(`Listening on Port ${PORT}`);
});