fix: use base URL for Supabase client, nginx proxies /rest/v1/ and /auth/v1/

The Supabase JS client auto-derives API paths from the base URL:
- REST: ${url}/rest/v1/
- Auth: ${url}/auth/v1/

Nginx now proxies these standard paths to the correct backend services.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 16:45:36 -04:00
parent a1a10abb8e
commit 1e640aa0c8
4 changed files with 9 additions and 10 deletions

View File

@@ -33,11 +33,9 @@ WORKDIR /app/calcpad-web
# Build-time env vars for Vite (inlined at build time) # Build-time env vars for Vite (inlined at build time)
ARG VITE_SUPABASE_URL ARG VITE_SUPABASE_URL
ARG VITE_SUPABASE_ANON_KEY ARG VITE_SUPABASE_ANON_KEY
ARG VITE_AUTH_URL
ARG VITE_COLLAB_WS_URL ARG VITE_COLLAB_WS_URL
ENV VITE_SUPABASE_URL=$VITE_SUPABASE_URL ENV VITE_SUPABASE_URL=$VITE_SUPABASE_URL
ENV VITE_SUPABASE_ANON_KEY=$VITE_SUPABASE_ANON_KEY ENV VITE_SUPABASE_ANON_KEY=$VITE_SUPABASE_ANON_KEY
ENV VITE_AUTH_URL=$VITE_AUTH_URL
ENV VITE_COLLAB_WS_URL=$VITE_COLLAB_WS_URL ENV VITE_COLLAB_WS_URL=$VITE_COLLAB_WS_URL
# Install dependencies first (layer caching) # Install dependencies first (layer caching)

View File

@@ -2,11 +2,14 @@ import { createClient } from '@supabase/supabase-js'
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL as string const supabaseUrl = import.meta.env.VITE_SUPABASE_URL as string
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY as string const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY as string
const authUrl = import.meta.env.VITE_AUTH_URL as string | undefined
/** /**
* Supabase client singleton. * Supabase client singleton.
* Returns null if env vars are not configured (local-only mode). * Returns null if env vars are not configured (local-only mode).
*
* The client auto-derives API paths from the base URL:
* - REST: ${supabaseUrl}/rest/v1/
* - Auth: ${supabaseUrl}/auth/v1/
*/ */
export const supabase = export const supabase =
supabaseUrl && supabaseAnonKey supabaseUrl && supabaseAnonKey
@@ -15,7 +18,6 @@ export const supabase =
persistSession: true, persistSession: true,
autoRefreshToken: true, autoRefreshToken: true,
detectSessionInUrl: true, detectSessionInUrl: true,
...(authUrl ? { url: authUrl } : {}),
}, },
}) })
: null : null

View File

@@ -69,9 +69,8 @@ services:
build: build:
context: . context: .
args: args:
VITE_SUPABASE_URL: ${SITE_URL:-http://localhost:8080}/rest VITE_SUPABASE_URL: ${SITE_URL:-http://localhost:8080}
VITE_SUPABASE_ANON_KEY: ${ANON_KEY} VITE_SUPABASE_ANON_KEY: ${ANON_KEY}
VITE_AUTH_URL: ${SITE_URL:-http://localhost:8080}/auth
VITE_COLLAB_WS_URL: ${COLLAB_WS_URL:-ws://localhost:8080/ws} VITE_COLLAB_WS_URL: ${COLLAB_WS_URL:-ws://localhost:8080/ws}
restart: unless-stopped restart: unless-stopped
ports: ports:

View File

@@ -10,8 +10,8 @@ server {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
} }
# Reverse proxy: PostgREST (database REST API) # Reverse proxy: PostgREST (Supabase client hits /rest/v1/*)
location /rest/ { location /rest/v1/ {
proxy_pass http://rest:3000/; proxy_pass http://rest:3000/;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@@ -19,8 +19,8 @@ server {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
# Reverse proxy: GoTrue (auth) # Reverse proxy: GoTrue auth (Supabase client hits /auth/v1/*)
location /auth/ { location /auth/v1/ {
proxy_pass http://auth:9999/; proxy_pass http://auth:9999/;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;