-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1.27 KB
/
index.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
const express = require("express");
const mongoose = require("mongoose");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const next = require("next");
const { MONGO_URI, SECRET } = require("./config");
const passport = require("./services/passport");
const AuthRoute = require("./routes/Auth");
const app = express();
const dev = process.env.NODE_ENV !== "production";
const nextApp = next({ dev });
const handle = nextApp.getRequestHandler();
const PORT = process.env.PORT || 5000;
nextApp.prepare().then(() => {
app.use(express.json());
app.use(
session({
secret: SECRET,
resave: false,
saveUninitialized: false,
cookie: { secure: false },
store: new MongoStore({
mongooseConnection: mongoose.connection,
}),
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use("/api/auth", AuthRoute);
app.get("*", (req, res) => {
handle(req, res);
});
mongoose
.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("conected to mongo database"))
.catch((e) => console.error(e));
app.listen(PORT, () => console.log(`listening on PORT ${PORT}`));
});