backend: update base path handling in room repository and helper
This commit is contained in:
parent
5ca46e59d8
commit
01c5b695d9
@ -10,7 +10,7 @@ import {
|
||||
} from '@openvidu-meet/typings';
|
||||
import { INTERNAL_CONFIG } from '../config/internal-config.js';
|
||||
import { MEET_ENV } from '../environment.js';
|
||||
import { getBasePath } from '../utils/html-injection.utils.js';
|
||||
import { getBasePath } from '../utils/html-dynamic-base-path.utils.js';
|
||||
|
||||
export class MeetRoomHelper {
|
||||
private constructor() {
|
||||
|
||||
@ -257,27 +257,14 @@ export class RoomRepository<TRoom extends MeetRoom = MeetRoom> extends BaseRepos
|
||||
* @returns The path portion of the URL without the basePath prefix
|
||||
*/
|
||||
private extractPathFromUrl(url: string): string {
|
||||
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 stripBasePath(url);
|
||||
return this.stripBasePath(url);
|
||||
}
|
||||
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
const pathname = stripBasePath(urlObj.pathname);
|
||||
const pathname = this.stripBasePath(urlObj.pathname);
|
||||
return pathname + urlObj.search + urlObj.hash;
|
||||
} catch {
|
||||
// If URL parsing fails, assume it's already a path
|
||||
@ -285,6 +272,24 @@ export class RoomRepository<TRoom extends MeetRoom = MeetRoom> extends BaseRepos
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the basePath from a given path if it starts with it.
|
||||
*
|
||||
* @param path - The path to process
|
||||
* @returns The path without the basePath prefix
|
||||
*/
|
||||
private stripBasePath(path: string): string {
|
||||
const basePath = getBasePath();
|
||||
// Remove trailing slash from basePath for comparison (e.g., '/meet/' -> '/meet')
|
||||
const basePathWithoutTrailingSlash = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
|
||||
|
||||
if (basePathWithoutTrailingSlash && path.startsWith(basePathWithoutTrailingSlash)) {
|
||||
return path.slice(basePathWithoutTrailingSlash.length) || '/';
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enriches room data by adding the base URL to access URLs.
|
||||
* Converts MongoDB document to domain object.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user