import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// In dev, proxy the API + uploads to the Express server so the SPA stays
// same-origin (cookies work) and matches the production setup where Express
// serves the built client.
export default defineConfig({
  plugins: [react()],
  server: {
    port: 5173,
    proxy: {
      '/api': { target: 'http://127.0.0.1:3000', changeOrigin: true },
      '/uploads': { target: 'http://127.0.0.1:3000', changeOrigin: true },
    },
  },
  build: {
    outDir: 'dist',
    // Don't inject the inline module-preload polyfill script — modern browsers all
    // support modulepreload, and an inline <script> would violate the server's
    // `script-src 'self'` CSP (see server/src/app.js). Keeps builds inline-free.
    modulePreload: { polyfill: false },
  },
})
