forked from advplyr/audiobookshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview-docs.js
More file actions
56 lines (50 loc) · 1.43 KB
/
Copy pathview-docs.js
File metadata and controls
56 lines (50 loc) · 1.43 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
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/**
* View Swagger documentation in browser
* Opens ReDoc documentation for the generated swagger-output.json
*/
const http = require('http')
const fs = require('fs')
const path = require('path')
const swaggerPath = path.join(__dirname, 'docs', 'swagger-output.json')
const port = 3004
if (!fs.existsSync(swaggerPath)) {
console.error('swagger-output.json not found. Run "node swagger.js" first.')
process.exit(1)
}
const html = `
<!DOCTYPE html>
<html>
<head>
<title>Audiobookshelf API Documentation</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url='/swagger.json'></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>
</html>
`
const server = http.createServer((req, res) => {
if (req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/html' })
res.end(html)
} else if (req.url === '/swagger.json') {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(fs.readFileSync(swaggerPath))
} else {
res.writeHead(404)
res.end('Not found')
}
})
server.listen(port, () => {
console.log(`ReDoc API documentation: http://localhost:${port}`)
})