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) <noreply@anthropic.com>
This commit is contained in:
SamoilenkoVadym 2026-02-09 14:47:11 +00:00
parent 114f5af81c
commit 0fbef069a8

View file

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