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

export default defineConfig({
  plugins: [react()],
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    copyPublicDir: true
  },
  preview: {
    port: 804,
    host: true,
    strictPort: true
  },
  server: {
    host: true, // Allow external access
    port: 5173,
    strictPort: true,
    proxy: {
      '/api': {
        target: 'http://localhost:804',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  define: {
    'process.env': {
      SMTP_HOST: process.env.SMTP_HOST,
      SMTP_PORT: process.env.SMTP_PORT,
      SMTP_SECURE: process.env.SMTP_SECURE,
      RECIPIENT_EMAIL: process.env.RECIPIENT_EMAIL,
      GOOGLE_EMAIL: process.env.GOOGLE_EMAIL,
      GOOGLE_APP_PASSWORD: process.env.GOOGLE_APP_PASSWORD,
      UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL,
      UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN
    }
  }
})
