From 37bb3414c8d0556edcedaddaefacbcc55933758b Mon Sep 17 00:00:00 2001 From: samanhappy Date: Tue, 27 May 2025 13:08:41 +0800 Subject: [PATCH] feat: add VITE_BASE_PATH environment variable and update routing in App component (#130) --- Dockerfile | 19 +++++++++++-------- frontend/src/App.tsx | 14 +++++++++++--- frontend/src/vite-env.d.ts | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb47dec..84e8750 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,20 +18,23 @@ RUN npm install -g pnpm ARG REQUEST_TIMEOUT=60000 ENV REQUEST_TIMEOUT=$REQUEST_TIMEOUT +ARG VITE_BASE_PATH="" +ENV VITE_BASE_PATH=$VITE_BASE_PATH + ENV PNPM_HOME=/usr/local/share/pnpm ENV PATH=$PNPM_HOME:$PATH RUN mkdir -p $PNPM_HOME && \ - pnpm add -g @amap/amap-maps-mcp-server @playwright/mcp@latest tavily-mcp@latest @modelcontextprotocol/server-github @modelcontextprotocol/server-slack + pnpm add -g @amap/amap-maps-mcp-server @playwright/mcp@latest tavily-mcp@latest @modelcontextprotocol/server-github @modelcontextprotocol/server-slack ARG INSTALL_EXT=false RUN if [ "$INSTALL_EXT" = "true" ]; then \ - ARCH=$(uname -m); \ - if [ "$ARCH" = "x86_64" ]; then \ - npx -y playwright install --with-deps chrome; \ - else \ - echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \ - fi; \ - fi + ARCH=$(uname -m); \ + if [ "$ARCH" = "x86_64" ]; then \ + npx -y playwright install --with-deps chrome; \ + else \ + echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \ + fi; \ + fi RUN uv tool install mcp-server-fetch diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 22ea3e5..2687561 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -13,16 +13,24 @@ import SettingsPage from './pages/SettingsPage'; import MarketPage from './pages/MarketPage'; import LogsPage from './pages/LogsPage'; +// Get base path from environment variable or default to empty string +const getBasePath = (): string => { + const basePath = import.meta.env.VITE_BASE_PATH || ''; + return basePath.startsWith('/') ? basePath : ''; +}; + function App() { + const basename = getBasePath(); + return ( - + {/* 公共路由 */} } /> - + {/* 受保护的路由,使用 MainLayout 作为布局容器 */} }> }> @@ -35,7 +43,7 @@ function App() { } /> - + {/* 未匹配的路由重定向到首页 */} } /> diff --git a/frontend/src/vite-env.d.ts b/frontend/src/vite-env.d.ts index 07e677c..c66c126 100644 --- a/frontend/src/vite-env.d.ts +++ b/frontend/src/vite-env.d.ts @@ -3,6 +3,7 @@ interface ImportMeta { readonly env: { readonly PACKAGE_VERSION: string; + readonly VITE_BASE_PATH?: string; // Add base path environment variable // Add other custom env variables here if needed [key: string]: any; };