diff --git a/lib/utils/__tests__/browser.spec.ts b/lib/utils/__tests__/browser.spec.ts index e99c30c4bb..a2e374874e 100644 --- a/lib/utils/__tests__/browser.spec.ts +++ b/lib/utils/__tests__/browser.spec.ts @@ -24,9 +24,9 @@ describe('getNewUrl()', () => { }); describe('getSubdomainPath()', () => { - it('should not modify the path that starts with /api', () => { - const result = getSubdomainPath('/api', { domain: 'charmverse' }); - expect(result).toEqual('/api'); + it('should not modify the path that starts with /api/', () => { + const result = getSubdomainPath('/api/foo', { domain: 'charmverse' }); + expect(result).toEqual('/api/foo'); }); it('should not return the path with subdomain when on subdomain host', () => { @@ -48,4 +48,9 @@ describe('getSubdomainPath()', () => { const result = getSubdomainPath('/charmverse', { domain: 'charmverse' }); expect(result).toEqual('/charmverse/charmverse'); }); + + it('should not strip out part of path when it include the domain', () => { + const result = getSubdomainPath('/charmverse-title', { domain: 'charmverse' }); + expect(result).toEqual('/charmverse/charmverse-title'); + }); }); diff --git a/lib/utils/browser.ts b/lib/utils/browser.ts index dac369a566..5ce0e93fe7 100644 --- a/lib/utils/browser.ts +++ b/lib/utils/browser.ts @@ -258,7 +258,7 @@ export function getSubdomainPath( config?: { domain: string; customDomain?: string | null }, host?: string ) { - if (path.startsWith('/api')) { + if (path.startsWith('/api/')) { return path; } @@ -267,18 +267,18 @@ export function getSubdomainPath( // strip out domain when using full custom domain if (customDomain && config?.domain && config.customDomain && customDomain === config.customDomain) { // remove space domain from path for custom domain - if (path.startsWith(`/${config.domain}`)) { - return path.replace(`/${config.domain}`, ''); + if (path.startsWith(`/${config.domain}/`)) { + return path.replace(`/${config.domain}/`, '/'); } - if (path.startsWith(`/${config.customDomain}`)) { - return path.replace(`/${config.customDomain}`, ''); + if (path.startsWith(`/${config.customDomain}/`)) { + return path.replace(`/${config.customDomain}/`, '/'); } } // strip out subdomain when using subdomain if (subdomain) { - return path.replace(new RegExp(`^\\/${subdomain}`), ''); + return path.replace(new RegExp(`^\\/${subdomain}\\/`), '/'); } // if we are not using a custom domain or subdomain, make sure that the space domain exists in the URL if (config && !customDomain && !path.startsWith(`/${config?.domain}/`)) {