Allow swagger.io to call us

This commit is contained in:
Christian Georgi
2020-11-16 18:21:06 +01:00
parent 3d24dc491d
commit 8e8ae949df
2 changed files with 6 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
"dependencies": { "dependencies": {
"@capire/common": "*", "@capire/common": "*",
"@sap/cds": "^4", "@sap/cds": "^4",
"cors": "^2.8.5",
"express": "^4.17.1" "express": "^4.17.1"
}, },
"scripts": { "scripts": {

View File

@@ -4,11 +4,15 @@ const readFile = promisify(require('fs').readFile)
const swaggerUi = require ('swagger-ui-express') const swaggerUi = require ('swagger-ui-express')
const cds = require ('@sap/cds') const cds = require ('@sap/cds')
const trace = cds.debug('openapi') const trace = cds.debug('openapi')
const cors = require('cors')
let app, host, docCache={} let app, host, docCache={}
cds cds
.on ('bootstrap', _app => { app = _app }) .on ('bootstrap', _app => {
app = _app
app.use(cors()) // allow to be called from e.g. editor.swagger.io
})
.on ('serving', service => { .on ('serving', service => {
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}`)