watch-party/frontend/vite.config.ts

45 lines
1.1 KiB
TypeScript

import path from "node:path";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
// Use PUBLIC_BASE_PATH="/watch-party/" for prod container builds.
// In dev, keep "/" so local paths are simple.
export default defineConfig(({ mode }) => {
// Load env from the repo root so both frontend and backend share the same .env.
const envDir = path.resolve(__dirname, "..");
const env = loadEnv(mode, envDir, "");
const base =
mode === "development"
? "/"
: env.PUBLIC_BASE_PATH || process.env.PUBLIC_BASE_PATH || "/watch-party/";
return {
envDir,
base,
plugins: [react()],
// DEV: proxy /api/* directly to Go backend
server: {
port: 5173,
open: true,
proxy: {
"/api": {
target: "http://localhost:8082",
changeOrigin: true,
},
},
},
// For `vite preview`, keep the same proxy
preview: {
proxy: {
"/api": {
target: "http://localhost:8082",
changeOrigin: true,
},
},
},
};
});