app.ts 689 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
2
3
import cookieParser from "cookie-parser";
import express, { Request, Response, NextFunction } from "express";
import router from "./routes";
Yoon, Daeki's avatar
Yoon, Daeki committed
4
5
6

const app = express();

Yoon, Daeki's avatar
Yoon, Daeki committed
7
8
9
10
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());

Kim, MinGyu's avatar
Kim, MinGyu committed
11
12
app.get('/', (req, res) => res.send('Hello World! 안녕하세요'))

Yoon, Daeki's avatar
Yoon, Daeki committed
13
14
15
16
17
18
19
20
21
22
23
app.use("/api", router);

app.use((err: any, req: Request, res: Response, next: NextFunction) => {
  console.log("익스프레스 에러: ", err);
  res.status(err.statusCode || 500).send(err.message || "서버 에러");
});

app.use(function (req, res, next) {
  res.status(404).send("잘못된 경로를 요청했습니다");
});

Yoon, Daeki's avatar
Yoon, Daeki committed
24
export default app;