-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.js
More file actions
45 lines (37 loc) · 1.42 KB
/
docs.js
File metadata and controls
45 lines (37 loc) · 1.42 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
45
import express from "express";
import path from "path";
import swaggerUi from "swagger-ui-express";
import { swaggerSpec } from "../../../swagger.config.js";
const baseDirectory = path.resolve();
const router = express.Router();
router.use("/api", swaggerUi.serve);
router.get("/api", swaggerUi.setup(swaggerSpec));
// Server jsDocs website
router.use("/server", express.static(getServerDocumentationPath()));
router.get("/server", (req, res) => {
res.sendFile(path.join(getServerDocumentationPath(), "index.html"));
});
// Frontend jsDocs website
router.use("/frontend", express.static(getFrontendDocumentationPath()));
router.get("/frontend", (req, res) => {
res.sendFile(path.join(getFrontendDocumentationPath(), "index.html"));
});
function getServerDocumentationPath() {
const docPath = path.join(baseDirectory, "server/documentation/jsdocs");
if (!docPath) {
throw new Error(
`Could not resolve server documentation build path. Ensure that you run \"npm run generate-docs\" in the base directory.`
);
}
return docPath;
}
function getFrontendDocumentationPath() {
const docPath = path.join(baseDirectory, "frontend/documentation/jsdocs");
if (!docPath) {
throw new Error(
`Could not resolve server documentation build path. Ensure that you run \"npm run generate-docs\" in the base directory.`
);
}
return docPath;
}
export default router;