import react from "@vitejs/plugin-react";
import { defineConfig, loadEnv } from "vite";

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  const queryServiceTarget = env.RPKI_EXPLORER_API_TARGET ?? "http://127.0.0.1:9557";

  return {
    plugins: [react()],
    server: {
      port: 5173,
      strictPort: false,
      proxy: {
        "/api/v1": {
          target: queryServiceTarget,
          changeOrigin: true
        }
      }
    },
    preview: {
      port: 5173,
      strictPort: true,
      proxy: {
        "/api/v1": {
          target: queryServiceTarget,
          changeOrigin: true
        }
      }
    }
  };
});
