-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (45 loc) · 1.27 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
const express = require("express");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const mongoose = require("mongoose");
const MongoStore = require("connect-mongo")(session);
const cors = require("cors");
const morgan = require("morgan");
const passport = require("passport");
const path = require("path");
const app = express();
require("dotenv").config({ path: ".env" });
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true
});
require("./models/User");
require("./passport");
app
.use(morgan("tiny"))
.use(cors())
.use(cookieParser())
.use(
session({
secret: process.env.SECRET,
key: process.env.KEY,
cookie: { maxAge: 14 * 24 * 60 * 60 * 1000 }, // 14 days
saveUninitialized: true,
resave: true,
store: new MongoStore({
mongooseConnection: mongoose.connection
})
})
)
.use(passport.initialize())
.use(passport.session());
const router = require("./routes");
app.use(router);
app.use(express.static(path.join(__dirname, "client/public")));
if (process.env.NODE_ENV === "production") {
app.get("*", (req, res) => {
res.sendFile(__dirname, "client/public/index.html");
});
}
module.exports = app;