Skip to content

Commit

Permalink
Allow relative service root paths (#152)
Browse files Browse the repository at this point in the history
The default value for option `apiPath` is now `/`, allowing more flexible control
over the root path where the CDS services are served.
Formerly, it was not possible to set root path _relative_  to the current host,
like `abc.com/1234-appid/$api-docs/...`, `abc.com/5678-appid/$api-docs/...`.
  • Loading branch information
chgeo authored Oct 2, 2024
1 parent 9325241 commit 56bf61f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

- The OpenAPI spec is no available for download on `.../openapi.json` and linked in the UI.

### Changed

- The default value for option `apiPath` is now `/`, allowing more flexible control over the root path where the CDS services are served. Formerly, it was not possible to set root path _relative_ to the current host, like `abc.com/1234-appid/$api-docs/...`, `abc.com/5678-appid/$api-docs/...`.

## Version 0.9.0 - 2024-07-15

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can set the most prominent options in `package.json` or `.cdsrc.json`, as in
"cds": {
"swagger": {
"basePath": "/$api-docs", // the root path to mount the middleware on
"apiPath": "", // the root path for the services (useful if behind a reverse proxy)
"apiPath": "/", // the root path for the services (useful if behind a reverse proxy)
"diagram": true, // whether to render the YUML diagram
"odataVersion": "4.0" // the OData Version to compile the OpenAPI specs. Defaults to 4.01
}
Expand Down
4 changes: 2 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { join } = require('path')
* @returns {express.RequestHandler} - an express middleware
*/
module.exports = (options={}, swaggerUiOptions={}) => {
options = Object.assign({ basePath: '/$api-docs', apiPath: '' }, options)
options = Object.assign({ basePath: '/$api-docs', apiPath: '/' }, options)

const router = express.Router()

Expand Down Expand Up @@ -44,7 +44,7 @@ function toOpenApiDoc (service, options = {}) {
cache[service.name] = openapi.compile(service.model, {
service: service.name,
'odata-version': options.odataVersion,
'openapi:url': join('/', options.apiPath, service.path),
'openapi:url': join(options.apiPath, service.path),
'openapi:diagram': ('diagram' in options ? options.diagram : true),
to: 'openapi' // workaround needed for cds-dk 7.4
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"swagger": {
"basePath": "/$api-docs",
"apiPath": "",
"apiPath": "/",
"diagram": true,
"odataVersion": ""
}
Expand Down

0 comments on commit 56bf61f

Please sign in to comment.