-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
56 lines (46 loc) · 1.34 KB
/
index.ts
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
import express from "express";
import expressSession from "express-session";
import passport from "passport";
import path from "path";
import dotenv from "dotenv";
import cors from "cors";
import connectRedis from "connect-redis";
import {
// connectToRedis,
connectToDatabase,
redisClient,
} from "./libs/database";
import authRoutes from "./routes/login";
import profRoutes from "./routes/prof";
import mypageRoutes from "./routes/mypage";
const RedisStore = require("connect-redis").default;
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
app.use(express.static(path.join(__dirname, "../client/build")));
app.use(authRoutes);
app.use(mypageRoutes);
app.use("/undergraduate_student", profRoutes);
dotenv.config();
connectToDatabase();
// connectToRedis();
app.use(
expressSession({
store: new RedisStore({ client: redisClient }),
secret: process.env.SESSION_KEY,
resave: false,
saveUninitialized: false,
cookie: { secure: false },
})
);
//passport middleware
app.use(passport.initialize());
app.use(passport.session());
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "../client/build", "index.html"));
});
const PORT = process.env.MAIN_PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});