Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix links for custom domain #5064

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/utils/__tests__/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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');
});
});
12 changes: 6 additions & 6 deletions lib/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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}/`)) {
Expand Down
Loading