-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathapp.js
63 lines (53 loc) · 1.69 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
require("dotenv").config();
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const mongoose = require("mongoose");
const erv = require("express-react-views");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const authRouter = require("./routes/authRouter");
const siteRouter = require("./routes/siteRouter");
const app = express();
// DB CONNECTION
mongoose
.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Connected to the DB."))
.catch((err) => console.log(err));
// VIEW ENGINE SETUP
app.set("views", __dirname + "/views");
app.set("view engine", "jsx");
app.engine("jsx", erv.createEngine());
// MIDDLEWARE
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
// SESSIONS MIDDLEWARE
app.use(
session({
secret: process.env.SESSION_SECRET,
// cookie: { maxAge: 3600000 * 1 }, // 1 hour // Time after which the cookie saved on the browser expires
resave: true,
saveUninitialized: false,
store: new MongoStore({
mongooseConnection: mongoose.connection,
ttl: 60 * 60 * 24 * 7,
// `ttl` Time to live - after which the session document saved
// in the DB expires - 7 days (14 days is the default if the option is not explicityl set)
}),
})
);
// ROUTES
app.use("/auth", authRouter);
app.use("/", siteRouter);
/* GET home page. */
app.get("/", (req, res, next) => {
res.render("Home");
});
module.exports = app;