-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (58 loc) · 1.75 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const session = require("express-session");
const firebase = require("./Config/fire-admin");
const express = require("express");
const studentRoutes = require("./Routes/student");
const staffRoutes = require("./Routes/staff");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const FirebaseStore = require("connect-session-firebase")(session);
const cors = require("cors");
require("dotenv").config();
const app = express();
app.use(
cors({
origin: [
"http://localhost:3000",
"http://localhost:3001",
"https://klvien.vercel.app",
"https://klvien.moganesan.tech",
"https://klvien-staffs.moganesan.tech",
"https://klvien-staffs.vercel.app",
],
method: ["GET", "POST"],
credentials: true,
exposedHeaders: ["set-cookie"],
})
);
//d
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
const SessionDB = new FirebaseStore({
database: firebase.database(),
});
if (process.env.NODE_ENV == "production") {
app.set("trust proxy", 4);
}
app.use(
session({
secret: process.env.SESSION_KEY,
resave: false,
saveUninitialized: false,
store: SessionDB,
name: "auth",
cookie: {
httpOnly: process.env.NODE_ENV == "production" ? true : false,
secure: process.env.NODE_ENV == "production" ? true : false,
sameSite: "none",
maxAge: 60 * 60 * 24 * 5 * 1000,
},
})
);
app.get("/", (req, res) => {
res.send(`Server Running On PORT: ${PORT}`);
});
app.use("/student", studentRoutes);
app.use("/staff", staffRoutes);
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => console.log(`Server running on PORT:${PORT}`));