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

const packageProxyTarget = process.env.PACKAGE_PROXY_TARGET
  || process.env.VITE_PACKAGE_BASE_URL
  || 'http://localhost:3000';

export default defineConfig({
  plugins: [react()],
  server: {
    port: 5173,
    strictPort: false,
    proxy: {
      '/api': {
        target: packageProxyTarget,
        changeOrigin: true
      },
      '/install-agent.sh': {
        target: packageProxyTarget,
        changeOrigin: true
      },
      '/uploads': {
        target: packageProxyTarget,
        changeOrigin: true
      },
      '/packages': {
        target: packageProxyTarget,
        changeOrigin: true
      }
    }
  },
  preview: {
    port: 4173,
    strictPort: false
  }
});
