unwind/unwind-ui/vite.config.ts
ducklet c63bee072f respect API_HOST & API_PORT env vars for dev
Using Vite's proxy option allows us to avoid CORS issues when the host
for Uvicorn doesn't match the host for Vite, e.g. localhost vs. 127.0.0.1.
2023-11-26 19:43:56 +01:00

29 lines
696 B
TypeScript

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()],
})