From 0fbef069a806557af4fa86b732cbed88fc8e2d64 Mon Sep 17 00:00:00 2001 From: SamoilenkoVadym Date: Mon, 9 Feb 2026 14:47:11 +0000 Subject: [PATCH] fix(backend): serve React frontend from FastAPI - Serve index.html on root / - Mount /assets for React static files - Backend now serves both frontend and API - Works with simple ProxyPass config Co-Authored-By: Claude Sonnet 4.5 (1M context) --- backend/app/main.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 63c331a..e8700a7 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -5,9 +5,11 @@ Main application entry point with CORS, middleware, and routers. from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import JSONResponse +from fastapi.responses import JSONResponse, FileResponse +from fastapi.staticfiles import StaticFiles from contextlib import asynccontextmanager import os +from pathlib import Path from app.api import auth, files, metadata, templates from app.api import import_api @@ -73,17 +75,26 @@ app.include_router(templates.router, prefix="/templates", tags=["templates"]) app.include_router(import_api.router, prefix="/import", tags=["import"]) -# Root endpoint +# Serve React frontend +STATIC_DIR = Path("/var/www/html/solventum-image-metadata") + @app.get("/") async def root(): - """Root endpoint - API info""" - return { - "name": "Oliver Metadata Tool API", - "version": "4.0.0", - "status": "running", - "docs": "/docs", - "redoc": "/redoc" - } + """Serve React index.html or API info""" + if STATIC_DIR.exists() and (STATIC_DIR / "index.html").exists(): + return FileResponse(str(STATIC_DIR / "index.html")) + else: + return { + "name": "Oliver Metadata Tool API", + "version": "4.0.0", + "status": "running", + "docs": "/docs", + "redoc": "/redoc" + } + +# Mount static files for React assets +if STATIC_DIR.exists(): + app.mount("/assets", StaticFiles(directory=str(STATIC_DIR / "assets")), name="assets") # Health check endpoint