generated from AnWhiteM/project-6_Front_End
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (30 loc) · 974 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
39
import express from "express";
import morgan from "morgan";
import cors from "cors";
import swaggerUi from "swagger-ui-express";
import swaggerDocument from "./swagger.json" assert { type: "json" };
import { v2 as cloudinary } from "cloudinary";
import router from "./routes/index.js";
import "./db/db.js";
const PORT = process.env.PORT || 8080;
const app = express();
app.use(morgan("dev"));
app.use(cors());
app.use(express.json());
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_KEY,
api_secret: process.env.CLOUDINARY_SECRET,
});
app.use("/", router);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use((req, res) => {
res.status(404).send("Route not found");
});
app.use((error, req, res, next) => {
const { status = 500, message = "Server error" } = error;
res.status(status).send({ message });
});
app.listen(PORT, () => {
console.info(`Server is running`);
});