-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
49 lines (34 loc) · 967 Bytes
/
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
import express, { Application } from 'express';
import route from './routes/route';
import "dotenv/config.js"
import cors from 'cors'
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient()
const app: Application = express();
app.use(cors({credentials:true,origin:"*"}))
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
async function start() {
try {
await prisma.$connect();
console.log('Terhubung ke database.');
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
} catch (error) {
console.error('Gagal terhubung ke database:', error);
}
finally {
await prisma.$disconnect();
}
}
// Panggil fungsi start untuk memulai server
start();
app.get('/', (req, res) => {
res.send("oke coy")
});
app.use('/api/',route)
const port: number = 3000;
app.listen(port, async () => {
console.log(`Server is running on port ${port}`);
});