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

const env = loadEnv('', process.cwd());
const allowedHosts = env.VITE_ALLOWED_HOSTS
  ? env.VITE_ALLOWED_HOSTS.split(',').map((host) => host.trim())
  : [];

export default defineConfig({
  plugins: [react()],
  server: {
    allowedHosts: allowedHosts,
    watch: {
      usePolling: true,
    },
    host: true,
    strictPort: true,
    proxy: {
      '/api': {
        target: 'http://localhost:5000',
        changeOrigin: true,
        secure: false,
      },
    },
  },
})
