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

const app = express();

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

app.use("/api", router);
13

14
app.use("/images", express.static(path.join(__dirname, "..", "/uploads")));
Kim, MinGyu's avatar
Kim, MinGyu committed
15
app.use("/images", express.static(path.join(__dirname, "..", "/adminpics")));
16

Yoon, Daeki's avatar
Yoon, Daeki committed
17
18
19
20
21
22
23
24
25
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
26
export default app;