Repository navigation
fix(postgrest): strip trailing slash from the base URL - #2862
pedroteixeira wants to merge 1 commit into
Conversation
PostgrestClient joins its base URL and the path with a slash
(`${this.url}/${relation}`, `${this.url}/rpc/${fn}`, `${this.url}/`), so
a base URL ending in '/' produced '//relation'. PostgREST answers that
with a 404 and an empty body. A bare origin passed through
`new URL(...).toString()` ('http://localhost:3001/') hits this.
The constructor now removes trailing slashes, which fixes from(), rpc(),
getOpenApiSpec() and the clients returned by schema(). URLs without a
trailing slash are unchanged. supabase-js already passes a URL without
one, so only standalone postgrest-js callers were affected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix Merge Risk:
|
🔍 Description
What changed?
The
PostgrestClientconstructor removes trailing slashes from the base URL.from(),rpc(),getOpenApiSpec()and clients fromschema()all build their URLs from it.Why was this change needed?
Request URLs are built as
${this.url}/${relation}, so a base URL ending in/requests//relation. PostgREST answers that with a 404 and an empty body, which is hard to trace back to the URL. A bare origin produces this naturally:new URL('/', location.origin).toString()gives'http://localhost:3001/'.This is about the client's base URL, not relation names (unlike #2278). supabase-js isn't affected, because it passes
new URL('rest/v1', …).href. Standalone postgrest-js users are. storage-js got the same normalisation in #1589.🔄 Breaking changes
URLs without a trailing slash are unchanged. The public
urlproperty now holds the normalised URL.📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formattingurlparameter📝 Additional notes
test/base-url.test.tscoversfrom,rpc,schema().fromandgetOpenApiSpecwith zero, one and two trailing slashes, using a mocked fetch.🤖 Generated with Claude Code