Skip to content

Commit

Permalink
add: api logger
Browse files Browse the repository at this point in the history
  • Loading branch information
pbc1017 committed Mar 19, 2024
1 parent 58d04a3 commit c72f6b1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions back/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ var bodyParser = require("body-parser");
app.use(bodyParser.json({ limit: "100mb" }));
app.use(bodyParser.urlencoded({ limit: "100mb", extended: true }));

app.use((req, res, next) => {
const start = Date.now(); // 요청 시작 시간

// 응답이 완료되었을 때 이벤트 리스너
res.on("finish", () => {
const duration = Date.now() - start; // 처리 시간
console.log(
`[${req.method}] ${req.url} - ${res.statusCode} [${duration}ms]`
);
});

next(); // 다음 미들웨어로 제어권을 넘김
});

sequelize
.sync({ force: false }) //true면 서버 실행마다 테이블 재생성
.then(() => {
Expand Down

0 comments on commit c72f6b1

Please sign in to comment.