3ea1bdbaf5
vite 代理若以 /park 为键会拦截 SPA 路由 /park,刷新时 GET /park 被代理到 server-core 返回 FastAPI 404。改为仅代理 /park/api(园区 API),SPA 路由 /park 走前端回退。
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { defineConfig, loadEnv } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
import { fileURLToPath, URL } from "node:url";
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const rootDir = fileURLToPath(new URL(".", import.meta.url));
|
|
const env = loadEnv(mode, rootDir, "");
|
|
|
|
return {
|
|
plugins: [react(), tailwindcss()],
|
|
resolve: {
|
|
alias: {
|
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
|
},
|
|
},
|
|
base: env.VITE_BASE_PATH || "/",
|
|
server: {
|
|
port: 5175,
|
|
proxy: {
|
|
// 开发期把 /api 与 /auth、/admin 代理到 server-core,避免跨域
|
|
"/api": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
|
"/auth": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
|
"/admin": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
|
// 仅代理 /park/api(园区 API),不要把 SPA 路由 /park 代理到后端,否则刷新返回 404
|
|
"/park/api": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
|
},
|
|
},
|
|
};
|
|
});
|