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

// Vite defaults.
const vite_host = "localhost"
const vite_port = 3000

const base = process.env.BASE_URL || "/"
const proxied_api_url = `http://${vite_host}:${vite_port}/api/`
const real_api_url = `http://${process.env.API_HOST}:${process.env.API_PORT}/api/`

// https://vitejs.dev/config/
export default defineConfig({
  base,
  define: {
    "process.env.API_URL": JSON.stringify(process.env.API_URL || proxied_api_url),
  },
  server: {
    host: vite_host,
    port: vite_port,
    proxy: {
      [`${base}api`]: {
        target: real_api_url,
        prependPath: false,
      },
    },
  },
  plugins: [vue()],
})
