-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (24 loc) · 803 Bytes
/
app.js
File metadata and controls
31 lines (24 loc) · 803 Bytes
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
import express, { json, urlencoded } from "express";
import morgan from "morgan";
import indexRouter from "./routes/index.js";
const app = express();
app.set("port", process.env.PORT || 3000);
app.use(morgan("dev"));
app.use(json());
app.use(urlencoded({ extended: false }));
app.use("/", indexRouter);
app.use((req, res, next) => {
const error = new Error(`${req.method} ${req.url} 라우터가 없습니다.`);
error.status = 404;
next(error);
});
app.use((err, req, res, next) => {
res.locals.message = err.message;
res.locals.error = process.env.NODE_ENV !== "production" ? err : {};
res.status(err.status || 500);
console.error(err);
res.send("Internal Server Error");
});
app.listen(app.get("port"), () => {
console.log(app.get("port"), "번 포트에서 대기중");
});