generated from gdsc-nits-org/penp-t
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
60 lines (50 loc) · 1.57 KB
/
server.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
59
60
import express from "express";
import cors from "cors";
import helmet from "helmet";
import morgan from "morgan";
import cookieParser from "cookie-parser";
import swaggerUI from "swagger-ui-express";
import YAML from "yamljs";
import * as Middlewares from "./src/middlewares";
import * as Routers from "./src/routers";
import * as Constants from "./src/globals/constants";
const app = express();
const corsOptions = {
origin: [
"http://localhost:3000",
"https://guidancegrid.gdscnits.in",
"https://guidance-grid.vercel.app",
],
credentials: true,
};
// Middlewares
app.use(cors(corsOptions))
.use(morgan("dev"))
.use(express.json())
.use(express.urlencoded({ extended: true }))
.use(cookieParser());
const swaggerDocument = YAML.load(Constants.System.DOCS);
app.use(
`${Constants.System.ROOT}/docs`,
swaggerUI.serve,
swaggerUI.setup(swaggerDocument, {
customCss: ".swagger-ui .topbar { display: none }",
customSiteTitle: "Guidance Grid API Docs",
})
);
app.use(helmet());
// Routers
app.use(`${Constants.System.ROOT}/`, Routers.Health);
app.use(`${Constants.System.ROOT}/auth`, Routers.Auth);
app.use(`${Constants.System.ROOT}/post`, Routers.Post);
app.use(`${Constants.System.ROOT}/profile`, Routers.Profile);
// Error Handlers
app.use(Middlewares.Error.errorHandler);
const server = app.listen(Constants.System.PORT, () => {
console.log(`Server started on port ${Constants.System.PORT}`);
});
process.addListener("SIGINT", () => {
console.log("exiting.....");
server.close();
process.exit(0);
});