-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (39 loc) · 1.24 KB
/
server.js
File metadata and controls
44 lines (39 loc) · 1.24 KB
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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const connectDB = require("./src/config/db");
const swaggerUi = require("swagger-ui-express");
const swaggerFile = require("./src/utils/swagger-output.json");
const port = process.env.PORT || 5000;
const authRoutes = require("./src/routes/authRoutes");
const bookRoutes = require("./src/routes/bookRoutes");
const CSS_URL =
"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.0/swagger-ui.min.css";
const app = express();
app.use(
cors({
origin: [
"https://mybookshelf-api-ferry.vercel.app",
"http://localhost:5000",
],
methods: ["GET", "POST", "PUT", "DELETE", "PATCH"],
allowedHeaders: ["Content-Type", "x-api-key"],
credentials: true,
})
);
app.use(express.json());
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerFile, {
customCss:
".swagger-ui .opblock .opblock-summary-path-description-wrapper { align-items: center; display: flex; flex-wrap: wrap; gap: 0 10px; padding: 0 10px; width: 100%; }",
customCssUrl: CSS_URL,
})
);
app.use("/api/books", bookRoutes);
app.use("/api/auth", authRoutes);
connectDB();
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});