-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (41 loc) · 1.42 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//==========package============
const express = require("express");
const makeLog = require('./src/modules/makelog');
//======Init========
const app = express()
const port = 8000
app.use(express.json())
require('dotenv').config()
const accountApi = require("./src/routers/account") // 소현
app.use("/account", accountApi)
const commentApi = require("./src/routers/comment") // 희주
app.use("/comment", commentApi)
const coupleApi = require("./src/routers/couple") // 소현
app.use("/couple", coupleApi)
const feedApi = require("./src/routers/feed") // 희주
app.use("/feed", feedApi)
const questionApi = require("./src/routers/question") // 소현
app.use("/question", questionApi)
const scheduleApi = require("./src/routers/schedule") // 희주
app.use("/schedule", scheduleApi)
// 공통 로깅 함수
async function logError(req, res, err) {
const logData = {
timestamp: new Date(),
message: err.message || '서버 오류',
status: err.status || 500,
};
await makeLog(req, res, logData);
res.status(err.status || 500).send({
success: false,
message: err.message || '서버 오류',
});
}
// 오류 처리 미들웨어
app.use(async (err, req, res, next) => {
await logError(req, res, err);
});
//======Web Server======
app.listen(port, () => {
console.log(`${port}번에서 HTTP 웹서버 실행`);
});