import { defineConfig, mergeConfig } from "vite";
import { commonViteConfig, getAllowedHosts } from "../common/config/vite.base";

const buildOutDir =
  process.env.ADMINFRONT_BUILD_OUT_DIR ?? "/tmp/baron-sso-adminfront-dist";

const allowedHosts = getAllowedHosts(
  ["sadmin.hmac.kr", "localhost", "172.16.10.176", "127.0.0.1"],
  undefined,
  undefined,
);

export default defineConfig(
  mergeConfig(commonViteConfig, {
    envPrefix: ["VITE_", "USERFRONT_", "ORGFRONT_"],
    cacheDir:
      process.env.ADMINFRONT_VITE_CACHE_DIR ??
      "/tmp/baron-sso-adminfront-vite-cache",
    build: {
      outDir: buildOutDir,
    },
    server: {
      host: "127.0.0.1",
      allowedHosts,
      proxy: {
        "/api": {
          target: process.env.API_PROXY_TARGET || "http://localhost:3000",
          changeOrigin: true,
        },
      },
    },
    preview: {
      host: "127.0.0.1",
      port: 5173,
      allowedHosts,
      proxy: {
        "/api": {
          target: process.env.API_PROXY_TARGET || "http://localhost:3000",
          changeOrigin: true,
        },
      },
    },
  }),
);
