import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from 'path' import { fileURLToPath } from 'url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) // One SPA at `/`. The auth screens keep /auth/* as *router* paths so the // backend's CONFIRM_EMAIL_PATH=/auth/confirm-email links resolve unchanged. // // `vite dev` and `vite preview` both serve index.html for unmatched paths, which // is what devserver.py's SPA_ROOTS hack used to fake — and they do it for every // path, not just /auth/. A CDN/S3 deploy needs an equivalent rewrite rule. export default defineConfig({ plugins: [react()], base: '/', build: { outDir: 'dist', emptyOutDir: true, sourcemap: true }, resolve: { alias: { '@': path.resolve(__dirname, 'src') } }, server: { port: 5173, // Same-origin style for local Vite when VITE_API_BASE is empty. // Requires API published on the host (docker-compose.host-ports.yml). // VITE_API_TARGET repoints the proxy when the API runs elsewhere // (e.g. 8001 locally because another service holds 8000). proxy: { '^/(health|users|roles|permissions|permission-tags|email|job|jobs|candidate|notes|interview|feedback|activity|pipeline|notifications|analytics|offers|tasks|assessments|org-settings|saved-searches|search|documents|sheet|managers|inbox|s3)(/|$)': { target: process.env.VITE_API_TARGET || 'http://127.0.0.1:8000', changeOrigin: true, // Several API prefixes double as SPA routes (/jobs, /inbox, …). // A browser NAVIGATION to one of them — refresh, pasted URL — // sends Accept: text/html and wants the app shell, not the API; // without this it proxied and 500'd. fetch/XHR traffic never // asks for text/html (downloads go fetch→blob), so only real // page loads are bypassed. bypass(req) { if (req.headers.accept?.includes('text/html')) return '/index.html' }, }, }, }, preview: { port: 4173 }, })