-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.ts
57 lines (47 loc) · 1.3 KB
/
app.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
57
import { Express } from "express";
import express from "express";
import authRoutes from "./auth/authRoutes";
import dashboardRoutes from "./dashboard/dashboardRoutes";
import passport from "passport";
import cors from "cors";
import dotenv from "dotenv";
const cookieSession = require("cookie-session");
//passportSetup must be required here so that it runs
const passportSetup = require("./auth/passport");
const app: Express = express();
dotenv.config({ path: "./.env" });
const corsConfig = {
origin: process.env.CORS_URL?.split(", "),
credentials: true,
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
allowedHeaders: [
"Content-Type",
"Origin",
"X-Requested-With",
"Accept",
"x-client-key",
"x-client-token",
"x-client-secret",
"Authorization",
],
};
app.use(cors(corsConfig));
app.options("*", cors(corsConfig));
app.use(express.json());
app.use(
cookieSession({
maxAge: 24 * 60 * 60 * 1000,
keys: [process.env.COOKIE_KEY],
sameSite: "none",
secure: true,
})
);
app.enable("trust proxy");
app.use(passport.initialize());
app.use(passport.session());
app.use("/auth", authRoutes);
app.use("/dashboard", dashboardRoutes);
app.listen({ port: 5000, host: "0.0.0.0" }, () => {
console.log("server is running");
});
export default app;