vignette/apps/web/vite.config.ts
2026-06-27 19:04:46 +09:00

54 lines
1.7 KiB
TypeScript

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// Vignette web — Vite + React 19.
// 개발 시 /api, /auth 프록시로 FastAPI(8000) 백엔드에 붙는다.
// 쿠키 인증(__Host-vignette_sid)을 위해 changeOrigin + 쿠키 전달.
const nodeEnv = (
globalThis as unknown as {
process?: { env?: { VITE_ALLOWED_HOSTS?: string; VITE_API_PROXY_TARGET?: string } };
}
).process?.env;
const defaultAllowedHosts = ["alpaca-home.taile93291.ts.net"];
const allowedHosts = Array.from(
new Set([
...defaultAllowedHosts,
...(nodeEnv?.VITE_ALLOWED_HOSTS ?? "")
.split(",")
.map((host: string) => host.trim())
.filter(Boolean),
]),
);
const apiProxyTarget = nodeEnv?.VITE_API_PROXY_TARGET?.trim() || "http://127.0.0.1:8000";
export default defineConfig({
plugins: [react()],
server: {
port: 5173,
...(allowedHosts.length ? { allowedHosts } : {}),
proxy: {
"/api": {
target: apiProxyTarget,
changeOrigin: true,
ws: true,
configure(proxy) {
proxy.on("proxyReq", (proxyReq, req) => {
const forwardedHost = req.headers.host;
if (forwardedHost) {
proxyReq.setHeader("x-forwarded-host", forwardedHost);
const hostName = String(forwardedHost).split(":")[0];
const forwardedProto = allowedHosts.includes(hostName) ? "https" : "http";
proxyReq.setHeader("x-forwarded-proto", forwardedProto);
}
});
},
// 백엔드 라우트는 /auth, /sessions, /health 로 노출되므로 /api 프리픽스 제거.
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
build: {
outDir: "dist",
sourcemap: false,
},
});