-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
55 lines (44 loc) · 1.26 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
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import helmet from "helmet";
import mongoSanitize from "express-mongo-sanitize";
const xss = require("xss-clean");
import coreRouter from "./routes/core.router";
import { mongoConnection } from "./mongoConnection";
import { apiLimiter } from "./utils";
dotenv.config({ path: ".env" });
export const app = express();
const whitelistedDomains = [
"https://coding-machine.pages.dev",
"https://coding-machine.siddharth9890.com",
];
if (process.env.NODE !== "production") {
whitelistedDomains.push("http://localhost:3000");
}
app.use(
cors({
origin: whitelistedDomains,
credentials: true,
})
);
app.use("/*", apiLimiter);
app.use(helmet());
app.use(mongoSanitize());
app.use(xss());
app.use(express.json({ limit: "5mb" }));
app.use(coreRouter);
if (process.env.NODE !== "production") {
console.log("comming from index.ts");
mongoConnection(app);
}
process.on("unhandledRejection", (error) => {
console.log(error);
console.log("SERVER CLOSING 😱 CALL THE ADMIN UNHANDLED REJECTION");
process.exit(1);
});
process.on("uncaughtException", (error) => {
console.log(error);
console.log("SERVER CLOSING 😱 CALL THE ADMIN UNCAUGHT EXCEPTION");
process.exit(1);
});