refactored redundant route

This commit is contained in:
Gamosoft 2026-01-05 11:13:54 +01:00
parent f87aafb9e9
commit 39c4486475
1 changed files with 4 additions and 17 deletions

View File

@ -322,18 +322,6 @@ pages_router = APIRouter(
# Application Routes (with auth via router dependencies) # Application Routes (with auth via router dependencies)
# ============================================================================ # ============================================================================
@pages_router.get("/", response_class=HTMLResponse)
async def root(request: Request):
"""Serve the main application page"""
index_path = static_path / "index.html"
async with aiofiles.open(index_path, 'r', encoding='utf-8') as f:
content = await f.read()
# Inject app name into title
app_name = config['app']['name']
content = content.replace('<title>NoteDiscovery</title>', f'<title>{app_name}</title>')
return content
@api_router.get("") @api_router.get("")
async def api_documentation(): async def api_documentation():
"""API Documentation - List all available endpoints""" """API Documentation - List all available endpoints"""
@ -1257,23 +1245,22 @@ async def health_check():
# Catch-all route for SPA (Single Page Application) routing # Catch-all route for SPA (Single Page Application) routing
# This allows URLs like /folder/note to work for direct navigation # This allows URLs like /folder/note to work for direct navigation
@pages_router.get("/{full_path:path}", response_class=HTMLResponse) @pages_router.get("/{full_path:path}", response_class=HTMLResponse)
@limiter.limit("120/minute")
async def catch_all(full_path: str, request: Request): async def catch_all(full_path: str, request: Request):
""" """
Serve index.html for all non-API routes. Serve index.html for all non-API routes (including root /).
This enables client-side routing (e.g., /folder/note) This enables client-side routing (e.g., /folder/note)
""" """
# Skip if it's an API route or static file (shouldn't reach here, but just in case) # Skip if it's an API route or static file (shouldn't reach here, but just in case)
if full_path.startswith('api/') or full_path.startswith('static/'): if full_path.startswith('api/') or full_path.startswith('static/'):
raise HTTPException(status_code=404, detail="Not found") raise HTTPException(status_code=404, detail="Not found")
# Serve index.html for all other routes # Serve index.html with app name injected
index_path = static_path / "index.html" index_path = static_path / "index.html"
async with aiofiles.open(index_path, 'r', encoding='utf-8') as f: async with aiofiles.open(index_path, 'r', encoding='utf-8') as f:
content = await f.read() content = await f.read()
# Inject app name into title
app_name = config['app']['name'] app_name = config['app']['name']
content = content.replace('<title>NoteDiscovery</title>', f'<title>{app_name}</title>') return content.replace('<title>NoteDiscovery</title>', f'<title>{app_name}</title>')
return content
# ============================================================================ # ============================================================================