-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (56 loc) · 1.65 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
const express = require("express");
const path = require("path");
require("dotenv").config();
const { SECRET, PORT } = process.env;
const {
getApp,
routeError,
appError,
} = require("./controllers/appController");
const session = require("express-session");
const { PrismaSessionStore } = require("@quixo3/prisma-session-store");
const { PrismaClient } = require("@prisma/client");
const passport = require("passport");
const authRouter = require("./routes/authRouter");
const fileRouter = require("./routes/fileRouter");
const folderRouter = require("./routes/folderRouter");
const app = express();
// prisma session store
app.use(
session({
store: new PrismaSessionStore(new PrismaClient(), {
checkPeriod: 2 * 60 * 1000,
dbRecordIdIsSessionId: true,
dbRecordIdFunction: undefined,
}),
secret: SECRET,
resave: true,
saveUninitialized: true,
cookie: {
maxAge: 7 * 24 * 60 * 60 * 1000,
},
})
);
// for passport.deserializeUser() to enable req.user
app.use(passport.session());
// set templates engine
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
// set public dir for serving static files
app.use(express.static(path.join(__dirname, "public")));
// parse form data
app.use(express.urlencoded({ extended: true }));
// parse json data
app.use(express.json());
require("./config/passport");
app.use((req, res, next) => {
res.locals.currentUser = req.user;
next();
});
app.use("/", authRouter);
app.use("/", fileRouter);
app.use("/", folderRouter);
app.get("/", getApp);
app.use(routeError);
app.use(appError);
app.listen(PORT, () => console.log(`Server listening on port ${PORT}`));