From eb2adc1ef9f0ca4e0ff26da49a59abc01641144a Mon Sep 17 00:00:00 2001 From: Pranav C Balan Date: Thu, 17 Jun 2021 19:59:58 +0530 Subject: [PATCH] fix: Generate swagger host and scheme genarated swagger scheme and host based on `NC_PUBLIC_URL` environment variable fixes #288 Signed-off-by: Pranav C Balan --- packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts index db6fddec35..a51fab5810 100644 --- a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts +++ b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts @@ -1508,9 +1508,13 @@ export class RestApiBuilder extends BaseApiBuilder { let swaggerBaseDocument: any = JSON.parse(JSON.stringify(await import('./ui/auth/swagger-base.xc.json'))); if (this.config?.auth?.jwt?.dbAlias !== this.connectionConfig.meta.dbAlias) { - swaggerBaseDocument = {...swaggerBaseDocument, tags: [], definitions: {}, paths: {}, host: req.get('host')}; + swaggerBaseDocument = {...swaggerBaseDocument, tags: [], definitions: {}, paths: {}}; } - + + const host = process.env.NC_PUBLIC_URL ? new URL(process.env.NC_PUBLIC_URL)?.host : req.get('host'); + const scheme = process.env.NC_PUBLIC_URL ? new URL(process.env.NC_PUBLIC_URL)?.protocol.slice(0, -1) : req.protocol; + swaggerBaseDocument.host = host; + swaggerBaseDocument.schemes = [scheme]; glob.sync(path.join(this.config.toolDir, 'nc', this.projectId, this.getDbAlias(), 'swagger', 'swagger.json')).forEach(jsonFile => { const swaggerJson = JSON.parse(fs.readFileSync(jsonFile, 'utf8')); swaggerBaseDocument.tags.push(...swaggerJson.tags);