import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { tanstackRouter } from "@tanstack/router-plugin/vite";
import tailwindcss from "@tailwindcss/vite";

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    tanstackRouter({ target: "react", autoCodeSplitting: true }),
    react(),
    tailwindcss(),
  ],
  server: {
    proxy: {
      "/ws": {
        target: "http://localhost:3000",
        ws: true,
        rewriteWsOrigin: true,
        configure: (proxy) => {
          proxy.on("error", (err) => {
            console.log("[ws proxy error]", err.message);
          });
          proxy.on("proxyReqWs", (_proxyReq, req) => {
            console.log("[ws proxy] forwarding", req.url);
          });
        },
      },
      "/api": { target: "http://localhost:3000", changeOrigin: true },
    },
  },
});
