render & serve API docs
This commit is contained in:
parent
2eb74c000b
commit
013a56ba26
3 changed files with 18 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -7,3 +7,6 @@ npm-debug.log
|
||||||
|
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
/dump.rdb
|
/dump.rdb
|
||||||
|
|
||||||
|
/docs/*.html
|
||||||
|
/docs/syntax.css
|
||||||
|
|
14
api.js
14
api.js
|
@ -6,11 +6,14 @@ const createHealthCheck = require('hafas-client-health-check')
|
||||||
const {createClient: createRedis} = require('redis')
|
const {createClient: createRedis} = require('redis')
|
||||||
const withCache = require('cached-hafas-client')
|
const withCache = require('cached-hafas-client')
|
||||||
const redisStore = require('cached-hafas-client/stores/redis')
|
const redisStore = require('cached-hafas-client/stores/redis')
|
||||||
|
const {join: pathJoin} = require('path')
|
||||||
|
const serveStatic = require('serve-static')
|
||||||
const pkg = require('./package.json')
|
const pkg = require('./package.json')
|
||||||
const stations = require('./routes/stations')
|
const stations = require('./routes/stations')
|
||||||
const station = require('./routes/station')
|
const station = require('./routes/station')
|
||||||
|
|
||||||
|
const docsRoot = pathJoin(__dirname, 'docs')
|
||||||
|
|
||||||
const berlinHbf = '8011160'
|
const berlinHbf = '8011160'
|
||||||
|
|
||||||
let hafas = createHafas(pkg.name)
|
let hafas = createHafas(pkg.name)
|
||||||
|
@ -54,13 +57,18 @@ const config = {
|
||||||
version: pkg.version,
|
version: pkg.version,
|
||||||
docsLink: 'https://github.com/derhuerst/db-rest/blob/5/docs/readme.md',
|
docsLink: 'https://github.com/derhuerst/db-rest/blob/5/docs/readme.md',
|
||||||
logging: true,
|
logging: true,
|
||||||
aboutPage: true,
|
aboutPage: false,
|
||||||
etags: 'strong',
|
etags: 'strong',
|
||||||
|
csp: `default-src 'none' style-src 'self' 'unsafe-inline'`,
|
||||||
healthCheck,
|
healthCheck,
|
||||||
modifyRoutes,
|
modifyRoutes,
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = createApi(hafas, config, () => {})
|
const api = createApi(hafas, config, (api) => {
|
||||||
|
api.use('/', serveStatic(docsRoot, {
|
||||||
|
extensions: ['html', 'htm'],
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
config,
|
config,
|
||||||
|
|
|
@ -31,13 +31,15 @@
|
||||||
"hafas-client-health-check": "^2.1.1",
|
"hafas-client-health-check": "^2.1.1",
|
||||||
"hafas-rest-api": "^3.3.0",
|
"hafas-rest-api": "^3.3.0",
|
||||||
"redis": "^3.0.2",
|
"redis": "^3.0.2",
|
||||||
"serve-buffer": "^2.0.0"
|
"serve-buffer": "^2.0.0",
|
||||||
|
"serve-static": "^1.14.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@derhuerst/technical-docs-cli": "^1.1.0",
|
||||||
"pino-pretty": "^4.0.0"
|
"pino-pretty": "^4.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"docs": "node api-docs.js >docs/api.md",
|
"docs": "node api-docs.js >docs/api.md && build-technical-doc --syntax-stylesheet-url /syntax.css <docs/readme.md >docs/index.html && build-technical-doc --syntax-stylesheet-url /syntax.css <docs/getting-started.md >docs/getting-started.html && build-technical-doc --syntax-stylesheet-url /syntax.css <docs/why.md >docs/why.html && build-technical-doc --syntax-stylesheet-url /syntax.css <docs/api.md >docs/api.html && build-technical-doc --syntax-stylesheet github >docs/syntax.css",
|
||||||
"build": "npm run docs",
|
"build": "npm run docs",
|
||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue