-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
65 lines (54 loc) · 1.78 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
59
60
61
62
63
64
65
import express, { NextFunction, Request, Response } from "express";
import dotenv from "dotenv";
import cors from "cors";
import swaggerUI from "swagger-ui-express";
import demoRoute from "./routes/demo";
import authRoute from "./routes/auth.route";
import propertyRoute from "./routes/property.route";
import paymentRoute from "./routes/payment.route";
import stripeRoute from "./routes/stripe.route";
import rentRoute from "./routes/rent.route";
import { authMiddleware } from "./utils/middlewares";
import fundDisburseCron from "./cronjobs/disbursement";
import swaggerFile from "./swagger/swagger.json";
import { wrappedResponse } from "./utils/functions";
import prisma from "./configs/prisma.config";
dotenv.config();
const app = express();
const port: number = parseInt(process.env.PORT || "8000");
app.use("/payment", express.raw({ type: "application/json" }), paymentRoute);
app.use(express.json());
app.use(
cors({
origin: "*",
})
);
app.use("/doc", swaggerUI.serve, swaggerUI.setup(swaggerFile));
app.use("/hello", authMiddleware, demoRoute);
app.use("/auth", authRoute);
app.use("/property", propertyRoute);
app.use("/rent", rentRoute);
app.use("/stripe", stripeRoute);
app.use("*", (_: Request, res: Response) => {
return wrappedResponse(res, "Not Found", 404, null);
});
app.use(function onError(
err: Error,
req: Request,
res: Response,
next: NextFunction
) {
console.log(err);
return wrappedResponse(res, err.message, 500, null);
});
const server = app.listen(port, async () => {
fundDisburseCron.start();
await prisma.$connect();
console.log(`⚡️[server]: Server is running on port ${port}`);
});
process.on("SIGINT", async () => {
await prisma.$disconnect();
fundDisburseCron.stop();
server.close();
console.log("[server]: Server closed on SIGINT");
});