-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (51 loc) · 1.3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require("express");
const cors = require("cors");
const swaggerUi = require("swagger-ui-express");
const swaggerJsDoc = require("swagger-jsdoc");
const attendanceRoutes = require("./src/attendance/routes");
// CDN CSS
const CSS_URL =
"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.3.0/swagger-ui.min.css";
const app = express();
const port = 5001;
// Enable CORS for all routes
app.use(cors());
// Parse JSON requests
app.use(express.json());
// Define root route
app.get("/", (req, res) => {
res.send("Hello, world!");
});
// Define attendance routes
app.use("/api/v1/attendance", attendanceRoutes);
// Swagger configuration
const swaggerOptions = {
definition: {
openapi: "3.0.0",
info: {
title: "Attendance Logging App",
version: "1.0.0",
description: "A simple Express Attendance Logging App",
},
servers: [
{
url: "http://localhost:5001",
},
{
url: "https://attendance-cyrus-11.vercel.app/",
},
],
},
apis: ["./src/attendance/*.js"],
};
const swaggerSpec = swaggerJsDoc(swaggerOptions);
// Serve Swagger UI
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerSpec,{ customCssUrl: CSS_URL })
);
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});