forked from goitacademy/nodejs-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (31 loc) · 874 Bytes
/
app.js
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
33
34
35
36
37
38
const express = require("express");
const logger = require("morgan");
const cors = require("cors");
const contactsRouter = require("./routes/api/contacts");
const authRouter = require("./routes/api/auth");
const app = express();
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((_, res, __) => {
res.status(404).json({
status: "error",
code: 404,
message: "Use api on routes: /api/contacts",
data: "Not found",
});
});
app.use((err, _, res, __) => {
console.log(err.stack);
res.status(500).json({
status: "fail",
code: 500,
message: err.message,
data: "Internal Server Error",
});
});
module.exports = app;