add typescript to backend
This commit is contained in:
parent
0a41568a2e
commit
30b28056de
10 changed files with 221 additions and 67 deletions
40
backend/src/index.ts
Normal file
40
backend/src/index.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
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 };
|
Loading…
Add table
Add a link
Reference in a new issue