From 2d85e9f2f8ffbbde075090832ddeed7535d8c56b Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 29 Oct 2025 02:31:52 +0800 Subject: [PATCH] Fix swagger docs page problem in dev mode - Add /static to VITE_API_ENDPOINTS - Update proxy rewrite rules - Include static file serving - Sync sample env file (cherry picked from commit ee7c683fa7268e91e3a8070e363bd7482ff195ba) --- lightrag_webui/.env.development | 4 ++ lightrag_webui/env.development.smaple | 4 +- lightrag_webui/vite.config.ts | 53 +++++---------------------- 3 files changed, 17 insertions(+), 44 deletions(-) create mode 100644 lightrag_webui/.env.development diff --git a/lightrag_webui/.env.development b/lightrag_webui/.env.development new file mode 100644 index 00000000..501be53c --- /dev/null +++ b/lightrag_webui/.env.development @@ -0,0 +1,4 @@ +# Development environment configuration +VITE_BACKEND_URL=http://localhost:9621 +VITE_API_PROXY=true +VITE_API_ENDPOINTS=/api,/documents,/graphs,/graph,/health,/query,/docs,/redoc,/openapi.json,/login,/auth-status,/static diff --git a/lightrag_webui/env.development.smaple b/lightrag_webui/env.development.smaple index 080cf95f..501be53c 100644 --- a/lightrag_webui/env.development.smaple +++ b/lightrag_webui/env.development.smaple @@ -1,2 +1,4 @@ # Development environment configuration -VITE_BACKEND_URL=/api +VITE_BACKEND_URL=http://localhost:9621 +VITE_API_PROXY=true +VITE_API_ENDPOINTS=/api,/documents,/graphs,/graph,/health,/query,/docs,/redoc,/openapi.json,/login,/auth-status,/static diff --git a/lightrag_webui/vite.config.ts b/lightrag_webui/vite.config.ts index f1d7faed..f39969c6 100644 --- a/lightrag_webui/vite.config.ts +++ b/lightrag_webui/vite.config.ts @@ -1,13 +1,9 @@ import { defineConfig } from 'vite' import path from 'path' +import { webuiPrefix } from '@/lib/constants' import react from '@vitejs/plugin-react-swc' import tailwindcss from '@tailwindcss/vite' -// Get the base URL from environment or default to / -const getBaseUrl = (): string => { - return process.env.VITE_BASE_URL || '/' -} - // https://vite.dev/config/ export default defineConfig({ plugins: [react(), tailwindcss()], @@ -16,44 +12,15 @@ export default defineConfig({ '@': path.resolve(__dirname, './src') } }, - base: getBaseUrl(), + // base: import.meta.env.VITE_BASE_URL || '/webui/', + base: webuiPrefix, build: { - outDir: 'dist', + outDir: path.resolve(__dirname, '../lightrag/api/webui'), emptyOutDir: true, - chunkSizeWarningLimit: 1000, + chunkSizeWarningLimit: 3800, rollupOptions: { - // Handle circular dependencies and module initialization - external: [], + // Let Vite handle chunking automatically to avoid circular dependency issues output: { - // Manual chunking strategy - manualChunks: { - // Group React-related libraries into one chunk - 'react-vendor': ['react', 'react-dom', 'react-router-dom'], - // Group graph visualization libraries into one chunk - 'graph-vendor': ['sigma', 'graphology', '@react-sigma/core'], - // Group UI component libraries into one chunk - 'ui-vendor': ['@radix-ui/react-dialog', '@radix-ui/react-popover', '@radix-ui/react-select', '@radix-ui/react-tabs'], - // Group utility libraries into one chunk - 'utils-vendor': ['axios', 'i18next', 'zustand', 'clsx', 'tailwind-merge'], - // Separate feature modules - 'feature-graph': ['./src/features/GraphViewer'], - 'feature-documents': ['./src/features/DocumentManager'], - 'feature-retrieval': ['./src/features/RetrievalTesting'], - - // Mermaid-related modules - 'mermaid-vendor': ['mermaid'], - - // Markdown-related modules - 'markdown-vendor': [ - 'react-markdown', - 'rehype-react', - 'rehype-raw', - 'remark-gfm', - 'remark-math', - 'react-syntax-highlighter', - 'unist-util-visit' - ] - }, // Ensure consistent chunk naming format chunkFileNames: 'assets/[name]-[hash].js', // Entry file naming format @@ -64,16 +31,16 @@ export default defineConfig({ } }, server: { - proxy: process.env.VITE_API_PROXY === 'true' && process.env.VITE_API_ENDPOINTS ? + proxy: import.meta.env.VITE_API_PROXY === 'true' && import.meta.env.VITE_API_ENDPOINTS ? Object.fromEntries( - process.env.VITE_API_ENDPOINTS.split(',').map(endpoint => [ + import.meta.env.VITE_API_ENDPOINTS.split(',').map(endpoint => [ endpoint, { - target: process.env.VITE_BACKEND_URL || 'http://localhost:9621', + target: import.meta.env.VITE_BACKEND_URL || 'http://localhost:9621', changeOrigin: true, rewrite: endpoint === '/api' ? (path) => path.replace(/^\/api/, '') : - endpoint === '/docs' || endpoint === '/openapi.json' ? + endpoint === '/docs' || endpoint === '/redoc' || endpoint === '/openapi.json' || endpoint === '/static' ? (path) => path : undefined } ])