fix: align drainage frontend configuration
This commit is contained in:
+7
-33
@@ -2,26 +2,17 @@ import tailwindcss from "@tailwindcss/vite";
|
||||
import react from "@vitejs/plugin-react-swc";
|
||||
import { defineConfig, loadEnv, type Plugin, type PreviewServer, type ViteDevServer } from "vite";
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import { createEdgeTtsMiddleware } from "./server/edge-tts-service";
|
||||
|
||||
const RUNTIME_CONFIG_PATH = "/runtime-config.js";
|
||||
|
||||
function renderRuntimeConfig(values: Record<string, string>) {
|
||||
const config = {
|
||||
DRAINAGE_MAPBOX_ACCESS_TOKEN:
|
||||
values.DRAINAGE_MAPBOX_ACCESS_TOKEN || values.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN || "",
|
||||
DRAINAGE_MAP_URL:
|
||||
values.DRAINAGE_MAP_URL ||
|
||||
values.NEXT_PUBLIC_MAP_URL ||
|
||||
"https://geoserver.waternetwork.cn/geoserver",
|
||||
DRAINAGE_GEOSERVER_WORKSPACE:
|
||||
values.DRAINAGE_GEOSERVER_WORKSPACE || values.NEXT_PUBLIC_GEOSERVER_WORKSPACE || "wenzhou",
|
||||
DRAINAGE_AGENT_API_BASE_URL:
|
||||
values.DRAINAGE_AGENT_API_BASE_URL ||
|
||||
values.NEXT_PUBLIC_AGENT_API_BASE_URL ||
|
||||
"http://127.0.0.1:8787",
|
||||
DRAINAGE_TTS_API_URL: values.DRAINAGE_TTS_API_URL || "/api/tts/edge",
|
||||
DRAINAGE_ENABLE_DEV_PANEL:
|
||||
values.DRAINAGE_ENABLE_DEV_PANEL || values.NEXT_PUBLIC_ENABLE_DEV_PANEL || "false",
|
||||
DRAINAGE_MAPBOX_ACCESS_TOKEN: values.DRAINAGE_MAPBOX_ACCESS_TOKEN || "",
|
||||
DRAINAGE_MAP_URL: values.DRAINAGE_MAP_URL || "https://geoserver.waternetwork.cn/geoserver",
|
||||
DRAINAGE_GEOSERVER_WORKSPACE: values.DRAINAGE_GEOSERVER_WORKSPACE || "wenzhou",
|
||||
DRAINAGE_AGENT_API_BASE_URL: values.DRAINAGE_AGENT_API_BASE_URL || "http://127.0.0.1:8787",
|
||||
DRAINAGE_ENABLE_DEV_PANEL: values.DRAINAGE_ENABLE_DEV_PANEL || "false",
|
||||
DRAINAGE_ENABLE_MSW: values.DRAINAGE_ENABLE_MSW || "false"
|
||||
};
|
||||
|
||||
@@ -30,6 +21,7 @@ function renderRuntimeConfig(values: Record<string, string>) {
|
||||
|
||||
function runtimeConfigPlugin(values: Record<string, string>): Plugin {
|
||||
const installMiddleware = (server: ViteDevServer | PreviewServer) => {
|
||||
server.middlewares.use(createEdgeTtsMiddleware());
|
||||
server.middlewares.use((request, response, next) => {
|
||||
if (request.url?.split("?", 1)[0] !== RUNTIME_CONFIG_PATH) {
|
||||
next();
|
||||
@@ -52,12 +44,6 @@ function runtimeConfigPlugin(values: Record<string, string>): Plugin {
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), "");
|
||||
const agentBaseUrl =
|
||||
env.AGENT_API_INTERNAL_BASE_URL ||
|
||||
env.DRAINAGE_AGENT_API_BASE_URL ||
|
||||
env.NEXT_PUBLIC_AGENT_API_BASE_URL ||
|
||||
"http://127.0.0.1:8787";
|
||||
const ttsBaseUrl = env.TTS_API_INTERNAL_BASE_URL || "http://127.0.0.1:8790";
|
||||
|
||||
return {
|
||||
plugins: [runtimeConfigPlugin(env), react(), tailwindcss()],
|
||||
@@ -66,18 +52,6 @@ export default defineConfig(({ mode }) => {
|
||||
"@": fileURLToPath(new URL("./src", import.meta.url))
|
||||
}
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
"/api/v1/agent/chat": {
|
||||
target: agentBaseUrl,
|
||||
changeOrigin: true
|
||||
},
|
||||
"/api/tts/edge": {
|
||||
target: ttsBaseUrl,
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
},
|
||||
test: {
|
||||
environment: "jsdom",
|
||||
globals: true,
|
||||
|
||||
Reference in New Issue
Block a user