backend: enhance getBaseUrl function to remove default ports for HTTPS and HTTP

This commit is contained in:
juancarmore 2025-10-14 09:58:20 +02:00
parent 376a388c22
commit 6d3329be2a

View File

@ -6,14 +6,26 @@ import { HttpContextService } from '../services/http-context.service.js';
* Returns the base URL for the application. * Returns the base URL for the application.
* *
* If the global `MEET_BASE_URL` variable is defined, it returns its value, * 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 * ensuring there is no trailing slash and removing default ports (443 for HTTPS, 80 for HTTP).
* from the `HttpContextService` instance. * Otherwise, it retrieves the base URL from the `HttpContextService` instance.
* *
* @returns {string} The base URL as a string. * @returns {string} The base URL as a string.
*/ */
export const getBaseUrl = (): string => { export const getBaseUrl = (): string => {
if (MEET_BASE_URL) { 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); const httpContextService = container.get(HttpContextService);