From 6d3329be2a47921766b04b777e6bc8fca5b06d15 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Tue, 14 Oct 2025 09:58:20 +0200 Subject: [PATCH] backend: enhance getBaseUrl function to remove default ports for HTTPS and HTTP --- backend/src/utils/url.utils.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/src/utils/url.utils.ts b/backend/src/utils/url.utils.ts index d1dcf4d..d1434c2 100644 --- a/backend/src/utils/url.utils.ts +++ b/backend/src/utils/url.utils.ts @@ -6,14 +6,26 @@ import { HttpContextService } from '../services/http-context.service.js'; * Returns the base URL for the application. * * If the global `MEET_BASE_URL` variable is defined, it returns its value, - * ensuring there is no trailing slash. Otherwise, it retrieves the base URL - * from the `HttpContextService` instance. + * ensuring there is no trailing slash and removing default ports (443 for HTTPS, 80 for HTTP). + * Otherwise, it retrieves the base URL from the `HttpContextService` instance. * * @returns {string} The base URL as a string. */ export const getBaseUrl = (): string => { if (MEET_BASE_URL) { - return MEET_BASE_URL.endsWith('/') ? MEET_BASE_URL.slice(0, -1) : MEET_BASE_URL; + let baseUrl = MEET_BASE_URL.endsWith('/') ? MEET_BASE_URL.slice(0, -1) : MEET_BASE_URL; + + // Remove default port 443 for HTTPS URLs + if (baseUrl.startsWith('https://') && baseUrl.includes(':443')) { + baseUrl = baseUrl.replace(':443', ''); + } + + // Remove default port 80 for HTTP URLs + if (baseUrl.startsWith('http://') && baseUrl.includes(':80')) { + baseUrl = baseUrl.replace(':80', ''); + } + + return baseUrl; } const httpContextService = container.get(HttpContextService);