feat: add VITE_BASE_PATH environment variable and update routing in App component (#130)

This commit is contained in:
samanhappy
2025-05-27 13:08:41 +08:00
committed by GitHub
parent c3e1fa1eee
commit 37bb3414c8
3 changed files with 23 additions and 11 deletions

View File

@@ -18,20 +18,23 @@ RUN npm install -g pnpm
ARG REQUEST_TIMEOUT=60000 ARG REQUEST_TIMEOUT=60000
ENV REQUEST_TIMEOUT=$REQUEST_TIMEOUT ENV REQUEST_TIMEOUT=$REQUEST_TIMEOUT
ARG VITE_BASE_PATH=""
ENV VITE_BASE_PATH=$VITE_BASE_PATH
ENV PNPM_HOME=/usr/local/share/pnpm ENV PNPM_HOME=/usr/local/share/pnpm
ENV PATH=$PNPM_HOME:$PATH ENV PATH=$PNPM_HOME:$PATH
RUN mkdir -p $PNPM_HOME && \ 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 ARG INSTALL_EXT=false
RUN if [ "$INSTALL_EXT" = "true" ]; then \ RUN if [ "$INSTALL_EXT" = "true" ]; then \
ARCH=$(uname -m); \ ARCH=$(uname -m); \
if [ "$ARCH" = "x86_64" ]; then \ if [ "$ARCH" = "x86_64" ]; then \
npx -y playwright install --with-deps chrome; \ npx -y playwright install --with-deps chrome; \
else \ else \
echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \ echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \
fi; \ fi; \
fi fi
RUN uv tool install mcp-server-fetch RUN uv tool install mcp-server-fetch

View File

@@ -13,16 +13,24 @@ import SettingsPage from './pages/SettingsPage';
import MarketPage from './pages/MarketPage'; import MarketPage from './pages/MarketPage';
import LogsPage from './pages/LogsPage'; 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() { function App() {
const basename = getBasePath();
return ( return (
<ThemeProvider> <ThemeProvider>
<AuthProvider> <AuthProvider>
<ToastProvider> <ToastProvider>
<Router> <Router basename={basename}>
<Routes> <Routes>
{/* 公共路由 */} {/* 公共路由 */}
<Route path="/login" element={<LoginPage />} /> <Route path="/login" element={<LoginPage />} />
{/* 受保护的路由,使用 MainLayout 作为布局容器 */} {/* 受保护的路由,使用 MainLayout 作为布局容器 */}
<Route element={<ProtectedRoute />}> <Route element={<ProtectedRoute />}>
<Route element={<MainLayout />}> <Route element={<MainLayout />}>
@@ -35,7 +43,7 @@ function App() {
<Route path="/settings" element={<SettingsPage />} /> <Route path="/settings" element={<SettingsPage />} />
</Route> </Route>
</Route> </Route>
{/* 未匹配的路由重定向到首页 */} {/* 未匹配的路由重定向到首页 */}
<Route path="*" element={<Navigate to="/" />} /> <Route path="*" element={<Navigate to="/" />} />
</Routes> </Routes>

View File

@@ -3,6 +3,7 @@
interface ImportMeta { interface ImportMeta {
readonly env: { readonly env: {
readonly PACKAGE_VERSION: string; readonly PACKAGE_VERSION: string;
readonly VITE_BASE_PATH?: string; // Add base path environment variable
// Add other custom env variables here if needed // Add other custom env variables here if needed
[key: string]: any; [key: string]: any;
}; };