整理代码

This commit is contained in:
2026-07-14 11:24:41 +08:00
parent 9d02c0a840
commit 7fac3c7f97
34 changed files with 53 additions and 38 deletions
+4 -14
View File
@@ -1,14 +1,11 @@
/**
* Vite 开发与构建配置。
* 开发环境将同源 /qhse_webapi 请求转发到正式接口域名,并从服务端环境变量注入 token。
* 开发环境将同源 /qhse_webapi 请求转发到正式接口域名,token 由浏览器请求统一携带。
*/
import { defineConfig, loadEnv } from "vite";
import { defineConfig } 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 {
export default defineConfig({
plugins: [vue()],
base: "./",
server: {
@@ -19,15 +16,8 @@ export default defineConfig(({ mode }) => {
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);
});
}
proxyTimeout: 15000
}
}
}
};
});