| |
| """ |
| Production server for uvify HuggingFace deployment |
| Serves both React frontend and FastAPI backend together |
| """ |
| import os |
| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| from fastapi.staticfiles import StaticFiles |
| from fastapi.responses import FileResponse |
| import uvify |
|
|
| |
| app = FastAPI( |
| title="Uvify", |
| description="Analyze GitHub repositories to generate uv commands", |
| version="1.0.0" |
| ) |
|
|
| |
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| |
| app.mount("/api", uvify.api, name="uvify_api") |
|
|
| |
| app.mount("/static", StaticFiles(directory="static"), name="static") |
|
|
| |
| @app.get("/") |
| async def serve_index(): |
| """Serve the React app index page""" |
| return FileResponse("static/index.html") |
|
|
| |
| @app.get("/{path:path}") |
| async def serve_frontend(path: str): |
| """Serve static files or fallback to React app for client-side routing""" |
| |
| if path.startswith("api/"): |
| return {"error": "API route not found"} |
| |
| |
| file_path = f"static/{path}" |
| if os.path.exists(file_path) and os.path.isfile(file_path): |
| return FileResponse(file_path) |
| |
| |
| return FileResponse("static/index.html") |
|
|
| if __name__ == "__main__": |
| import uvicorn |
| port = int(os.environ.get("PORT", 7860)) |
| uvicorn.run(app, host="0.0.0.0", port=port) |