import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import tailwindcss from "@tailwindcss/vite";

// The web app talks ONLY to the API Server. The production build is written into
// ../server/dist so the Go BFF can embed it. In dev, /api is proxied to the API
// Server so we avoid CORS and can use same-origin relative URLs in the client.
export default defineConfig({
  plugins: [vue(), tailwindcss()],
  build: {
    outDir: "../server/dist",
    emptyOutDir: true,
  },
  server: {
    port: 5173,
    // Listen on all interfaces so the dev server is reachable on the LAN
    // (e.g. http://10.2.1.101:5173 from another device).
    host: true,
    // Allow access via the LAN hostname/IP (Vite's host check otherwise blocks
    // non-localhost Host headers). true = accept any host (fine for LAN dev).
    allowedHosts: true,
    proxy: {
      "/api": {
        target: process.env.VITE_API_TARGET || "http://localhost:8080",
        changeOrigin: true,
      },
    },
  },
});
