Files
DataGovernanceDashboard/next/vite.config.ts
T
2026-07-14 10:56:51 +08:00

34 lines
1.1 KiB
TypeScript

/**
* Vite 开发与构建配置。
* 开发环境将同源 /qhse_webapi 请求转发到正式接口域名,并从服务端环境变量注入 token。
*/
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import type { ClientRequest } from "node:http";
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "QHSE_");
return {
plugins: [vue()],
base: "./",
server: {
port: 18081,
proxy: {
"/qhse_webapi": {
target: "https://qhse.cncecoa.com",
changeOrigin: true,
secure: true,
timeout: 15000,
proxyTimeout: 15000,
configure(proxy) {
// QHSE_ 变量仅存在于 Node 侧,不能使用会暴露到浏览器的 VITE_ 前缀。
(proxy as unknown as { on: (event: string, callback: (request: ClientRequest) => void) => void }).on("proxyReq", (proxyRequest) => {
if (env.QHSE_API_TOKEN) proxyRequest.setHeader("token", env.QHSE_API_TOKEN);
});
}
}
}
}
};
});