forked from Bohdan100/so-yummy-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (40 loc) · 1.33 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
43
44
45
46
47
48
49
50
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 { HttpError } = require("./helpers");
const {
authRouter,
recipesRouter,
favoriteRouter,
shoppingListRouter,
ownRecipesRouter,
ingredientsRouter,
searchRouter,
popularRecipesRouter,
subscribeRouter,
} = require("./routes/api");
const app = express();
const formatsLogger = app.get("env") === "development" ? "dev" : "short";
app.use(logger(formatsLogger));
app.use(cors());
app.use(express.json());
app.use("/api/auth", authRouter);
app.use("/api/recipes", recipesRouter);
app.use("/api/favorite", favoriteRouter);
app.use("/api/shopping-list", shoppingListRouter);
app.use("/api/ownRecipe", ownRecipesRouter);
app.use("/api/ingredients", ingredientsRouter);
app.use("/api/search", searchRouter);
app.use("/api/popular-recipes", popularRecipesRouter);
app.use("/api/subscribe", subscribeRouter);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use((error, req, res, next) => {
if (HttpError) {
return res.status(error.status).json({ message: error.message });
}
res.status(500).json({ message: `Internal server error: ${error.message}` });
});
module.exports = app;