-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
58 lines (47 loc) · 1.3 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
57
58
import express from "express";
import cors from "cors";
import helmet from "helmet";
import cookieParser from "cookie-parser";
const xss = require("xss-clean");
import dotenv from "dotenv";
import routes from "./routes";
import { makeConnectionWithDB } from "./db";
import loadData from "./insertData";
import { loadA2ZSheet } from "./script";
import { limiter } from "./src/utils/rateLimiter";
dotenv.config();
const app = express();
const PORT = process.env.PORT || 5000;
app.use(limiter);
app.use(helmet());
app.use(xss());
app.use(cookieParser());
let urlsCors = ["https://cs-tracker.vercel.app"];
if (process.env.NODE !== "production") {
urlsCors.push("http://localhost:3000");
}
app.use(
cors({
origin: urlsCors,
credentials: true,
})
);
async function makeDatabase() {
await makeConnectionWithDB();
}
app.use(express.json({ limit: "5kb" }));
routes(app);
app.listen(PORT, async () => {
await makeDatabase();
console.log("Server running on Port: ", PORT);
});
process.on("unhandledRejection", (error) => {
console.log(error);
console.log("SERVER CLOSING 😱 CALL THE SUPPORT UNHANDLED REJECTION");
process.exit(1);
});
process.on("uncaughtException", (error) => {
console.log(error);
console.log("SERVER CLOSING 😱 CALL THE SUPPORT UNCAUGHT EXCEPTION");
process.exit(1);
});