From b08bb10f63d4158ecca21d6a0663b483c9d8556b Mon Sep 17 00:00:00 2001 From: cruizba Date: Tue, 3 Feb 2026 01:56:58 +0100 Subject: [PATCH] backend: fix URL path extraction to remove basePath prefix --- .../src/repositories/room.repository.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/meet-ce/backend/src/repositories/room.repository.ts b/meet-ce/backend/src/repositories/room.repository.ts index dd457ddf..7d828bb0 100644 --- a/meet-ce/backend/src/repositories/room.repository.ts +++ b/meet-ce/backend/src/repositories/room.repository.ts @@ -2,6 +2,7 @@ import { MeetRoom, MeetRoomFilters, MeetRoomStatus } from '@openvidu-meet/typing import { inject, injectable } from 'inversify'; import { MeetRoomDocument, MeetRoomModel } from '../models/mongoose-schemas/room.schema.js'; import { LoggerService } from '../services/logger.service.js'; +import { getBasePath } from '../utils/html-injection.utils.js'; import { getBaseUrl } from '../utils/url.utils.js'; import { BaseRepository } from './base.repository.js'; @@ -211,20 +212,35 @@ export class RoomRepository extends BaseRepos } /** - * Extracts the path from a URL, removing the base URL if present. + * Extracts the path from a URL, removing the base URL and basePath if present. + * This ensures only the route path is stored in the database, without the basePath prefix. * * @param url - The URL to process - * @returns The path portion of the URL + * @returns The path portion of the URL without the basePath prefix */ private extractPathFromUrl(url: string): string { - // If already a path, return as-is + const basePath = getBasePath(); + // Remove trailing slash from basePath for comparison (e.g., '/meet/' -> '/meet') + const basePathWithoutTrailingSlash = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath; + + // Helper to strip basePath from a path + const stripBasePath = (path: string): string => { + if (basePathWithoutTrailingSlash !== '' && path.startsWith(basePathWithoutTrailingSlash)) { + return path.slice(basePathWithoutTrailingSlash.length) || '/'; + } + + return path; + }; + + // If already a path, strip basePath and return if (url.startsWith('/')) { - return url; + return stripBasePath(url); } try { const urlObj = new URL(url); - return urlObj.pathname + urlObj.search + urlObj.hash; + const pathname = stripBasePath(urlObj.pathname); + return pathname + urlObj.search + urlObj.hash; } catch { // If URL parsing fails, assume it's already a path return url;