add typescript to backend
This commit is contained in:
parent
0a41568a2e
commit
30b28056de
10 changed files with 221 additions and 67 deletions
|
@ -1,41 +0,0 @@
|
|||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
const { PrismaClient } = require("@prisma/client");
|
||||
const appRoutes = require("./routes/appRoutes");
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
function setupMiddleware(app) {
|
||||
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