Skip to content

Commit 1f71bcd

Browse files
committed
Feat: swagger preview
1 parent 151bdd0 commit 1f71bcd

File tree

5 files changed

+631
-39
lines changed

5 files changed

+631
-39
lines changed

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
const express = require("express");
33
const { json } = require("express");
4+
const swaggerJsDoc = require("swagger-jsdoc");
5+
const swaggerUi = require("swagger-ui-express");
46
const app = express();
57
const PORT = process.env.PORT || 8000;
68

@@ -9,8 +11,29 @@ const menuRoutes = require("./routes/menuRoutes.js");
911

1012
app.use(json());
1113

14+
// Swagger definition
15+
const swaggerOptions = {
16+
swaggerDefinition: {
17+
openapi: "3.0.0",
18+
info: {
19+
title: "Food Delivery Platform API",
20+
version: "1.0.0",
21+
description: "API documentation for the Food Delivery Platform",
22+
},
23+
servers: [
24+
{
25+
url: `http://localhost:${PORT}`,
26+
},
27+
],
28+
},
29+
apis: ["./routes/*.js"],
30+
};
31+
32+
const swaggerDocs = swaggerJsDoc(swaggerOptions);
33+
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
34+
1235
app.get('/', (req, res) => {
13-
res.send('<h1>Welcome to Food Delivery Platform</h1>');
36+
res.redirect('/api-docs');
1437
});
1538

1639
// Routes

0 commit comments

Comments
 (0)