import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; // Dev server proxies /auth, /rest, /realtime, /storage to the local Supabase // stack so the app can use relative URLs (works in Docker + localhost). const SUPABASE_TARGET = 'http://127.0.0.1:54321'; export default defineConfig(({ mode }) => ({ plugins: [react()], server: { host: true, port: 3001, proxy: { '/auth/v1': { target: SUPABASE_TARGET, changeOrigin: true }, '/rest': { target: SUPABASE_TARGET, changeOrigin: true }, '/realtime': { target: SUPABASE_TARGET, changeOrigin: true, ws: true }, '/storage': { target: SUPABASE_TARGET, changeOrigin: true }, '/functions': { target: SUPABASE_TARGET, changeOrigin: true }, // Sessionize sync sidecar (run `npm run sidecar:dev` to start it). // Strip the /sidecar prefix so /sidecar/run -> http://127.0.0.1:3002/run // (mirrors the nginx `location /sidecar/ { proxy_pass .../; }` rewrite). '/sidecar': { target: loadEnv(mode, '.', 'SIDECAR_').SIDECAR_TARGET || 'http://127.0.0.1:3002', changeOrigin: true, rewrite: (path) => path.replace(/^\/sidecar/, ''), }, }, }, }));