forked from goitacademy/nodejs-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (24 loc) · 785 Bytes
/
app.js
File metadata and controls
32 lines (24 loc) · 785 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
32
import express from "express";
import logger from "morgan";
import cors from "cors";
import contactsRouter from "./routes/api/contacts.js";
import authRouter from "./routes/api/auth.js";
import dotenv from "dotenv";
dotenv.config();
const app = express();
app.use(logger("combined"));
const formatsLogger = app.get("env") === "development" ? "dev" : "short";
app.use(logger(formatsLogger));
app.use(cors());
app.use(express.json());
app.use(express.static("public"));
app.use("/api/users", authRouter);
app.use("/api/contacts", contactsRouter);
app.use((req, res) => {
res.status(404).json({ message: "Not found" });
});
app.use((err, req, res, next) => {
const { status = 500, message = "Server error" } = err;
res.status(status).json({ message });
});
export default app;