Skip to content

fix(postgrest): strip trailing slash from the base URL - #2862

Open
pedroteixeira wants to merge 1 commit into
supabase:masterfrom
pedroteixeira:fix/postgrest-trailing-slash
Open

pedroteixeira wants to merge 1 commit into
supabase:masterfrom
pedroteixeira:fix/postgrest-trailing-slash

Conversation

@pedroteixeira

Copy link
Copy Markdown

🔍 Description

What changed?

The PostgrestClient constructor removes trailing slashes from the base URL. from(), rpc(), getOpenApiSpec() and clients from schema() 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/'.

const db = new PostgrestClient('http://localhost:3001/')
await db.from('users').select() // GET http://localhost:3001//users → 404

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

  • This PR contains no breaking changes

URLs without a trailing slash are unchanged. The public url property now holds the normalised URL.

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run pnpm nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable) — JSDoc of the url parameter

📝 Additional notes

test/base-url.test.ts covers from, rpc, schema().from and getOpenApiSpec with zero, one and two trailing slashes, using a mocked fetch.

🤖 Generated with Claude Code

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>
@pedroteixeira
pedroteixeira requested review from a team as code owners November 15, 2026 19:19
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Client URLs now consistently omit trailing slashes, preventing unexpected request URLs when using endpoints with one or more trailing slashes.

The PostgrestClient constructor converts the supplied URL to a string and removes all trailing slashes before storing it. New tests check request URLs for relation, RPC, schema-scoped relation, and OpenAPI requests when the base URL has no trailing slash, one trailing slash, or repeated trailing slashes. A separate test covers a bare origin ending in a slash.

Change: Bug fix

Merge Risk: Minimal · up to 94a7d

This change normalizes trailing slashes in the PostgREST client base URL so request URLs no longer contain doubled slashes. URLs without a trailing slash behave as before. No actionable merge-blocking risk was found.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 550535a5-c4c4-4c64-94c7-309f5bae7107
Commits

Reviewing files that changed from the base of the PR and between 13211d9 and 94a7da5.

Files selected for processing: 2

  • packages/core/postgrest-js/src/PostgrestClient.ts
  • packages/core/postgrest-js/test/base-url.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant