From e8751d04a32848c8493e07d920c2b8143a020f52 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Sat, 30 Nov 2024 10:00:00 +0100 Subject: [PATCH] Refactor: adapt the api logic to use apiPath environment variable --- api/src/attachment/schemas/attachment.schema.ts | 2 +- api/src/config/index.ts | 1 - api/src/config/types.ts | 1 - api/src/websocket/pipes/io-message.pipe.ts | 2 +- api/src/websocket/utils/socket-request.ts | 4 +--- 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/api/src/attachment/schemas/attachment.schema.ts b/api/src/attachment/schemas/attachment.schema.ts index 6d042ba5..c68cfa9c 100644 --- a/api/src/attachment/schemas/attachment.schema.ts +++ b/api/src/attachment/schemas/attachment.schema.ts @@ -91,7 +91,7 @@ export class Attachment extends BaseSchema { attachmentName: string = '', ): string { return buildURL( - config.parameters.apiUrl, + config.apiPath, `/attachment/download/${attachmentId}/${attachmentName}`, ); } diff --git a/api/src/config/index.ts b/api/src/config/index.ts index 5cb430a6..ccc24576 100644 --- a/api/src/config/index.ts +++ b/api/src/config/index.ts @@ -112,7 +112,6 @@ export const config: Config = { ? Number(process.env.UPLOAD_MAX_SIZE_IN_BYTES) : 2000000, appName: 'Hexabot.ai', - apiUrl: 'http://localhost:4000', appUrl: 'http://localhost:8081', }, pagination: { diff --git a/api/src/config/types.ts b/api/src/config/types.ts index 7b472909..27f05ea7 100644 --- a/api/src/config/types.ts +++ b/api/src/config/types.ts @@ -81,7 +81,6 @@ export type Config = { storageMode: 'disk' | 'memory'; maxUploadSize: number; appName: string; - apiUrl: string; appUrl: string; }; pagination: { diff --git a/api/src/websocket/pipes/io-message.pipe.ts b/api/src/websocket/pipes/io-message.pipe.ts index 3754f07f..798ad5ab 100644 --- a/api/src/websocket/pipes/io-message.pipe.ts +++ b/api/src/websocket/pipes/io-message.pipe.ts @@ -49,7 +49,7 @@ export class IOMessagePipe implements PipeTransform { const url = message.url.startsWith('http') ? message.url - : `${config.parameters.apiUrl}${message.url}`; + : `${config.apiPath}${message.url}`; if (!URL.canParse(url)) { throw new BadRequestException('Cannot parse url'); diff --git a/api/src/websocket/utils/socket-request.ts b/api/src/websocket/utils/socket-request.ts index cd1d459f..25c5fab3 100644 --- a/api/src/websocket/utils/socket-request.ts +++ b/api/src/websocket/utils/socket-request.ts @@ -90,9 +90,7 @@ export class SocketRequest { // Resolve the URL and path const urlObj = new URL( - this.url.startsWith('http') - ? this.url - : `${config.parameters.apiUrl}${this.url}`, + this.url.startsWith('http') ? this.url : `${config.apiPath}${this.url}`, ); this.path = urlObj.pathname || '/';