-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
42 lines (31 loc) · 1.2 KB
/
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
39
40
41
42
const express = require("express");
const logger = require("morgan");
const cors = require("cors");
require("dotenv").config();
const swaggerUi = require("swagger-ui-express");
const swaggerDocument = require("./swagger.json");
const authRouter = require("./routes/api/auth-routes");
const noticesRouter = require("./routes/api/notices-routes");
const newsRouter = require("./routes/api/news-routes");
const servicesRouter = require("./routes/api/services-routes");
const userRouter = require("./routes/api/user-routes");
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-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use("/api/auth", authRouter);
app.use("/api/services", servicesRouter);
app.use("/api/news", newsRouter);
app.use("/api/user", userRouter);
app.use("/api/notices", noticesRouter);
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 });
});
module.exports = app;