Skip to content

Commit c0ec700

Browse files
committed
Add mui and swagger docs
1 parent c9a8925 commit c0ec700

File tree

6 files changed

+759
-39
lines changed

6 files changed

+759
-39
lines changed

backend/question-service/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
const express = require("express");
22
const dotenv = require("dotenv");
33
const path = require("path");
4+
const swaggerUi = require("swagger-ui-express");
5+
const yaml = require("yaml");
6+
const fs = require("fs");
47

58
const envFilePath = path.join(
69
path.resolve(path.dirname(path.dirname(__dirname))),
7-
".env"
10+
".env",
811
);
912

13+
const file = fs.readFileSync("./swagger.yml", "utf-8");
14+
const swaggerDocument = yaml.parse(file);
15+
1016
dotenv.config({ path: envFilePath });
1117

1218
const app = express();
1319

1420
const PORT = process.env.QUESTION_SERVICE_PORT || 3000;
1521

1622
app.get("/", (req, res) => {
17-
res.json({ message: "Hello World from question-service" });
23+
res.status(200).json({ message: "Hello World from question-service" });
1824
});
1925

26+
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
27+
2028
app.listen(PORT, () => console.log(`Listening on port ${PORT}`));

backend/question-service/package-lock.json

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/question-service/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
"description": "",
1313
"dependencies": {
1414
"axios": "^1.7.7",
15+
"body-parser": "^1.20.3",
1516
"dotenv": "^16.4.5",
1617
"express": "^4.20.0",
17-
"mongoose": "^8.6.1"
18+
"mongoose": "^8.6.1",
19+
"swagger-ui-express": "^5.0.1",
20+
"yaml": "^2.5.1"
1821
},
1922
"devDependencies": {
2023
"@eslint/js": "^9.10.0",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
openapi: 3.0.0
2+
3+
info:
4+
title: Question Service
5+
version: 1.0.0
6+
7+
paths:
8+
/:
9+
get:
10+
tags:
11+
- root
12+
summary: Root
13+
description: Ping the server
14+
responses:
15+
"200":
16+
description: Successful Response
17+
content:
18+
application/json:
19+
schema:
20+
type: object
21+
properties:
22+
message:
23+
type: string
24+
description: Message

0 commit comments

Comments
 (0)