-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (29 loc) · 861 Bytes
/
server.js
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
require('dotenv').config();
const http = require('http');
const cors = require('cors');
const express = require('express');
const routes = require('./routes/index.js');
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const corsOption = {
origin: '*',
};
const app = express();
app.use(cors(corsOption));
app.use(express.json());
app.use(routes);
app.get('/ping', (req, res) => {
res.json({ message: 'pong' });
});
const server = http.createServer(app);
const PORT = process.env.PORT || 10010;
const start = async () => {
// 서버를 시작하는 함수입니다.
try {
server.listen(PORT, () => console.log(`Server is listening on ${PORT}`));
} catch (err) {
console.error(err);
await prisma.$disconnect(); // 에러가 발생했을 시에 database 연결을 종료합니다.
}
};
start();