generated from leveorxyz/express-boilerplate-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
executable file
·47 lines (37 loc) · 1.04 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
import express, { Application, NextFunction, Request, Response } from "express";
import dotenv from "dotenv";
import cors from "cors";
import quizRouter from "./routes/quiz.router";
import prisma from "./configs/prisma.config";
import { wrappedResponse } from "./utils/functions";
dotenv.config();
const app: Application = express();
const port: number = parseInt(process.env.PORT || "8000");
app.use(express.json());
app.use(
cors({
origin: "*",
})
);
app.use("/quiz", quizRouter);
app.use("*", (_: Request, res: Response) => {
return wrappedResponse(res, false, [404], null, 404);
});
app.use(function onError(
err: Error,
req: Request,
res: Response,
next: NextFunction
) {
console.log(err);
return wrappedResponse(res, false, [500], null, 500);
});
const server = app.listen(port, async () => {
await prisma.$connect();
console.log(`⚡️[server]: Server is running on PORT ${port}`);
});
process.on("SIGINT", async () => {
await prisma.$disconnect();
server.close();
console.log("[server]: Server closed on SIGINT");
});