Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/lib/stores/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export function getApiEndpoint(region?: string): string {
const hostname = url.host; // "hostname:port" (or just "hostname" if no port)

// If instance supports multi-region, add the region subdomain.
const subdomain = isMultiRegionSupported(url) ? getSubdomain(region) : '';
let subdomain = isMultiRegionSupported(url) ? getSubdomain(region) : '';
if (subdomain && hostname.startsWith(subdomain)) {
subdomain = '';
}

return `${protocol}//${subdomain}${hostname}/v1`;
Comment on lines +57 to 62
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No tests added for the new guard

The getApiEndpoint function is called in many places across the codebase, yet there are no unit tests for this particular fix. A test covering at least the two key scenarios would make the intention clear and prevent regressions:

  1. APPWRITE_ENDPOINT = "https://fra.cloud.appwrite.io" + getApiEndpoint('fra') → should return https://fra.cloud.appwrite.io/v1 (no duplicate prefix)
  2. APPWRITE_ENDPOINT = "https://cloud.appwrite.io" + getApiEndpoint('fra') → should return https://fra.cloud.appwrite.io/v1 (prefix added normally)

Without tests, it is difficult to verify the fix is correct and to protect against future regressions.

}
Expand Down
Loading