app.ts 771 Bytes
Newer Older
1
import cookieParser from "cookie-parser";
2
3
import * as dotenv from "dotenv";
dotenv.config();
4
import express, { Request, Response, NextFunction } from "express";
5
import path from "path";
6
import router from "./routes";
Yoon, Daeki's avatar
Yoon, Daeki committed
7
8
const app = express();

9
10
11
12
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());

13
14
app.use("/images", express.static(path.join(__dirname, "..", "/uploads")));

15
16
17
18
19
20
21
22
23
24
25
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
26
export default app;