From 379f7a6e44e190de16aa13c3a9f71844a6e93dd3 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Wed, 22 Oct 2025 11:20:14 -0400 Subject: [PATCH] fix: web interface --- start_web.py | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 start_web.py diff --git a/start_web.py b/start_web.py new file mode 100644 index 0000000..0829752 --- /dev/null +++ b/start_web.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +""" +NFOGuard Web Interface Starter +Simple script to start web interface using existing config system +""" +import os +import sys +import uvicorn +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse + +# Import existing configuration +from config.settings import config + +# Import existing database and components +from core.database import NFOGuardDatabase + +# Import web routes from existing system +from api.web_routes import register_web_routes + + +def create_web_app() -> FastAPI: + """Create FastAPI web application""" + app = FastAPI( + title="NFOGuard Web Interface", + description="Web interface for NFOGuard media database management", + version="2.7.0-web", + docs_url=None, # Disable docs in production + redoc_url=None + ) + + return app + + +def setup_static_files(app: FastAPI) -> None: + """Mount static file directories""" + static_path = os.path.join(os.path.dirname(__file__), "nfoguard-web", "static") + logo_path = os.path.join(os.path.dirname(__file__), "logo") + + if os.path.exists(static_path): + app.mount("/static", StaticFiles(directory=static_path), name="static") + + if os.path.exists(logo_path): + app.mount("/logo", StaticFiles(directory=logo_path), name="logo") + + # Serve index.html at root + @app.get("/") + async def serve_index(): + index_file = os.path.join(static_path, "index.html") + if os.path.exists(index_file): + return FileResponse(index_file) + else: + return {"message": "NFOGuard Web Interface", "status": "running"} + + +def main(): + """Main entry point for NFOGuard Web Interface""" + print("🌐 Starting NFOGuard Web Interface...") + + # Use existing config system + web_host = os.environ.get("WEB_HOST", "0.0.0.0") + web_port = int(os.environ.get("WEB_PORT", "8081")) + + print(f"šŸ“Š Configuration: Port {web_port}") + + # Create FastAPI app + app = create_web_app() + + # Initialize database using existing system + try: + db = NFOGuardDatabase() + print(f"āœ… Connected to database: {config.db_host}:{config.db_port}/{config.db_name}") + except Exception as e: + print(f"āŒ Failed to connect to database: {e}") + sys.exit(1) + + # Create dependencies for dependency injection + dependencies = { + "db": db, + "config": config + } + + # Setup static files and routes + setup_static_files(app) + + # Register web routes + register_web_routes(app, dependencies) + + print(f"šŸš€ Starting web server on {web_host}:{web_port}") + + try: + uvicorn.run( + app, + host=web_host, + port=web_port, + workers=1, + log_level="info", + access_log=False + ) + except KeyboardInterrupt: + print("\nšŸ›‘ Web interface shutdown by user") + except Exception as e: + print(f"āŒ Web interface failed: {e}") + sys.exit(1) + + +if __name__ == "__main__": + main() \ No newline at end of file