From 74dc21725b67b79f0d5514dc691e51ab59c98ae1 Mon Sep 17 00:00:00 2001 From: jrcleber Date: Fri, 31 May 2024 20:05:54 +0000 Subject: [PATCH] env:BASE_URL --- .env.dev | 4 ++++ docs/swagger.yaml | 6 +++--- src/config/scala.config.ts | 13 ++++++++++++- src/main.ts | 10 +++++----- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.env.dev b/.env.dev index d6d27190..29fb68a6 100644 --- a/.env.dev +++ b/.env.dev @@ -81,6 +81,10 @@ REDIS_ENABLED=false REDIS_URI=redis://localhost:6379 REDIS_PREFIX=codechat +# Domínio em que a documetação será exibida +# EX.: v1.dodmain.com +BASE_URL= + # https://min.io/docs/minio/linux/index.html S3_ENABLED=false S3_ACCESS_KEY=access_key_id diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 595a425a..88bf30b3 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -55,7 +55,7 @@ info: can build stronger and more authentic relationships with their customers, generating lasting satisfaction and loyalty. [![Run in Postman](https://run.pstmn.io/button.svg)](https://www.postman.com/codechat/workspace/codechat-whatsapp-api/api/fbe06c7b-7647-4c71-81ee-841f5b2e90d8?action=share&creator=14064846) - version: 1.3.0 + version: 1.3.1 contact: name: jrCleber email: cleber@codechat.dev @@ -1265,7 +1265,7 @@ paths: summary: Delete Message description: | This endpoint is used to delete a message for everyone in a chat instance. - It requires the `instanceName` parameter in the path and the `messageId` parameter in the query. + It requires the `instanceName` parameter in the path and the `id` parameter in the query. parameters: - name: instanceName in: path @@ -1274,7 +1274,7 @@ paths: required: true description: '- required' example: 'codechat_v1' - - name: messageId + - name: id in: query schema: type: string diff --git a/src/config/scala.config.ts b/src/config/scala.config.ts index 51756553..813cce9d 100644 --- a/src/config/scala.config.ts +++ b/src/config/scala.config.ts @@ -35,15 +35,26 @@ import { Router } from 'express'; import { join } from 'path'; import YAML from 'yamljs'; import { apiReference } from '@scalar/express-api-reference'; +import { readFileSync } from 'fs'; const router = Router(); +const yamlFile = readFileSync(join(process.cwd(), 'docs', 'swagger.yaml'), { + encoding: 'utf8', +}); + +const json = YAML.parse(yamlFile); + +if (process.env?.BASE_URL) { + json.servers[0].variables.prod_host.default = process.env?.BASE_URL; +} + export const docsRouter = router.use( '/docs', apiReference({ spec: { content() { - return YAML.load(join(process.cwd(), 'docs', 'swagger.yaml')); + return json; }, }, }), diff --git a/src/main.ts b/src/main.ts index cf9bf640..773320d1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,6 @@ * │ See the License for the specific language governing permissions and │ * │ limitations under the License. │ * │ │ - * │ @function initWA @param undefined │ * | @function bootstrap @param undefined │ * ├──────────────────────────────────────────────────────────────────────────────┤ * │ @important │ @@ -57,10 +56,11 @@ export async function bootstrap() { logger.log('HTTP' + ' - ON: ' + httpServer.PORT); new Logger(configService, 'Swagger Docs').warn( ` - ┌──────────────────────────────┐ - │ Swagger Docs │ - │ http://localhost:${httpServer.PORT}/docs │ - └──────────────────────────────┘`.replace(/^ +/gm, ' '), + .. + . Swagger Docs + . http://localhost:${httpServer.PORT}/docs + . https://${process.env?.BASE_URL || 'no-value'}/docs + .. `.replace(/^ +/gm, ' '), ); });