import express, { Express } from "express"; import cors from "cors"; import { PrismaClient } from "@prisma/client"; import appRoutes from "./routes/appRoutes"; const app: Express = express(); const port = process.env.PORT || 3000; const prisma = new PrismaClient(); function setupMiddleware(app: Express) { app.use(cors()); app.use(express.json()); app.use("/api", appRoutes); } setupMiddleware(app); // Start server async function startServer() { try { app.listen(port); console.log(`Server is running on http://localhost:${port}`); } catch (error) { console.error("Error starting the server:", error); } } process.on("SIGINT", async () => { try { await prisma.$disconnect(); console.log("Prisma client disconnected"); process.exit(0); } catch (error) { console.error("Error disconnecting Prisma client:", error); process.exit(1); } }); startServer(); module.exports = { app, prisma };