""" VNEWS Clean Backend - serves static/index_v2.html directly. No injection layers. All APIs from existing modules preserved. Comments feature REMOVED per user request. """ import sys, os # Import the full chain which registers all API endpoints on the FastAPI app from app_main import app, _search_all, _clean # Now override the root '/' to serve our clean frontend from fastapi import Query, Request from fastapi.responses import HTMLResponse, FileResponse, JSONResponse from fastapi.staticfiles import StaticFiles import os # Remove old '/' route app.router.routes = [r for r in app.router.routes if not ( getattr(r, 'path', None) == '/' and 'GET' in getattr(r, 'methods', set()) )] # Remove comment endpoints (user requested removal) app.router.routes = [r for r in app.router.routes if not ( getattr(r, 'path', None) in ('/api/short/comments', '/api/short/comment') )] # Mount static files STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static') app.mount('/static', StaticFiles(directory=STATIC_DIR), name='static') @app.get('/') async def serve_index(): """Serve the clean v2 frontend - single HTML file, no injection.""" index_path = os.path.join(STATIC_DIR, 'index_v2.html') if os.path.exists(index_path): return FileResponse(index_path, media_type='text/html') return HTMLResponse('
index_v2.html not found
', status_code=500) # Keep /api/hashtag/sources using direct search (not Google News) # This was already overridden in app_main.py with _search_all # Just make sure it's accessible # Storage status endpoint @app.get('/api/storage_status') def storage_status(): """Check if persistent storage is enabled.""" data_dir = '/data' persistent = os.path.isdir(data_dir) and os.access(data_dir, os.W_OK) return JSONResponse({'persistent': persistent, 'path': data_dir}) # Categories for the tab bar @app.get('/api/categories') def get_categories(): """Return category list for frontend tab bar.""" return JSONResponse([]) # Categories moved into News tab, homepage shows media content # Share page @app.get('/s') async def share_page(url: str = '', title: str = '', img: str = ''): """OG share page for social media.""" html = f''' Redirecting...''' return HTMLResponse(html)