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 ee7c683fa7)
This commit is contained in:
yangdx 2025-10-29 02:31:52 +08:00 committed by Raphaël MANSUY
parent 8c7b0017df
commit 2d85e9f2f8
3 changed files with 17 additions and 44 deletions

View file

@ -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

View file

@ -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

View file

@ -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
}
])