Remove need for host to swagger UI
This commit is contained in:
@@ -6,7 +6,7 @@ const cds = require ('@sap/cds')
|
|||||||
const trace = cds.debug('openapi')
|
const trace = cds.debug('openapi')
|
||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
|
|
||||||
let app, host, docCache={}
|
let app, docCache={}
|
||||||
|
|
||||||
cds
|
cds
|
||||||
.on ('bootstrap', _app => {
|
.on ('bootstrap', _app => {
|
||||||
@@ -17,16 +17,15 @@ cds
|
|||||||
const apiPath = '/api-docs'+service.path
|
const apiPath = '/api-docs'+service.path
|
||||||
console.log (`[Open API] - serving ${service.name} at ${apiPath}`)
|
console.log (`[Open API] - serving ${service.name} at ${apiPath}`)
|
||||||
app.use(apiPath, async (req, _, next) => {
|
app.use(apiPath, async (req, _, next) => {
|
||||||
req.swaggerDoc = await toOpenApiDoc(service, host, docCache)
|
req.swaggerDoc = await toOpenApiDoc(service, docCache)
|
||||||
next()
|
next()
|
||||||
}, swaggerUi.serve, swaggerUi.setup())
|
}, swaggerUi.serve, swaggerUi.setup())
|
||||||
addLinkToIndexHtml(service, apiPath)
|
addLinkToIndexHtml(service, apiPath)
|
||||||
})
|
})
|
||||||
.on ('listening', ({server})=> { host = 'localhost:'+server.address().port })
|
|
||||||
|
|
||||||
async function toOpenApiDoc(service, host, cache) {
|
async function toOpenApiDoc(service, cache) {
|
||||||
if (!cache[service.name]) {
|
if (!cache[service.name]) {
|
||||||
const spec = await openApiFromFile(service, host)
|
const spec = await openApiFromFile(service)
|
||||||
if (spec) { // pre-compiled spec file available?
|
if (spec) { // pre-compiled spec file available?
|
||||||
cache[service.name] = spec
|
cache[service.name] = spec
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user