-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
37 lines (29 loc) · 959 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
const path = require("path");
const helmet = require("helmet");
const cors = require("cors");
const express = require("express");
const swaggerSpec = require("./api/swagger");
const swaggerUi = require("swagger-ui-express");
const { restricted } = require("./api/auth/authMiddleware");
const app = express();
app.use(cors());
app.use(
helmet({
contentSecurityPolicy: false,
})
);
app.use(express.json());
app.use(express.static(path.join(__dirname, "/client/build")));
app.use("/api/auth", require("./api/auth/authRouter"));
app.use("/api/recipes", restricted, require("./api/recipes/recipesRouter"));
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.get("/*", (req, res) => {
res.sendFile(path.join(__dirname + "/client/build", "index.html"));
});
app.use((err, req, res, next) => { //eslint-disable-line
res.status(err.status || 500).json({
message: err.message,
source: err.source,
});
});
module.exports = app;