import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import tailwindcss from "@tailwindcss/vite"
import path from "node:path"

export default defineConfig({
  plugins: [react(), tailwindcss()],
  resolve: {
    alias: { "@": path.resolve(__dirname, "./src") },
  },
  server: {
    proxy: {
      // Dev: /api → FastAPI-Backend (Override via MC_API_TARGET, z.B. die Box)
      "/api": { target: process.env.MC_API_TARGET || "http://127.0.0.1:9000", changeOrigin: true },
      // Web-Terminals (ttyd) laufen same-origin über den MC2-Reverse-Proxy (/<name>/ + /<name>/ws).
      "/console": { target: process.env.MC_API_TARGET || "http://127.0.0.1:9000", changeOrigin: true, ws: true },
      "/hermes-terminal": { target: process.env.MC_API_TARGET || "http://127.0.0.1:9000", changeOrigin: true, ws: true },
      // Eingebaute Hermes-Web-GUI (hermes serve) — same-origin über den MC2-Reverse-Proxy, mit WS.
      "/hermes-ui": { target: process.env.MC_API_TARGET || "http://127.0.0.1:9000", changeOrigin: true, ws: true },
    },
  },
  build: { outDir: "dist" },
})
