Files
life-echo/app-eval-web/vite.config.ts

66 lines
2.0 KiB
TypeScript
Raw Normal View History

import react from "@vitejs/plugin-react";
import { loadEnv } from "vite";
import { defineConfig } from "vitest/config";
/**
* VITE_EVAL_API_BASE /internal/... Vite
* api/development.sh INTERNAL_EVAL_PORT 7999
* VITE_EVAL_PROXY_TARGET=http://127.0.0.1:8001 npm run dev
*/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const proxyTarget =
(env.VITE_EVAL_PROXY_TARGET || "").trim() ||
"http://127.0.0.1:7999";
/** 消费者主站 main:app对话 / 回忆录 JWT API默认 :8000 */
const mainApiProxy =
(env.VITE_MAIN_API_PROXY_TARGET || "").trim() ||
"http://127.0.0.1:8000";
return {
plugins: [react()],
server: {
port: 5174,
proxy: {
"/internal": {
target: proxyTarget,
changeOrigin: true,
/** 后端未启动时默认 Vite 控制台几乎无输出;这里打出直连目标便于对照 API 终端。 */
configure: (proxy) => {
proxy.on("error", (err) => {
console.error(
`[vite proxy] /internal → ${proxyTarget} failed:`,
(err as Error).message,
"(请在该地址启动 Internal Eval API默认 api 目录下 :7999)",
);
});
},
},
"/api": {
target: mainApiProxy,
changeOrigin: true,
configure: (proxy) => {
proxy.on("error", (err) => {
console.error(
`[vite proxy] /api → ${mainApiProxy} failed:`,
(err as Error).message,
"(请启动主站 API main:app默认 :8000)",
);
});
},
},
"/ws": {
target: mainApiProxy,
ws: true,
changeOrigin: true,
},
},
},
test: {
environment: "node",
include: ["src/**/*.test.ts"],
},
};
});