Kacemath's picture
feat: update with latest changes
47bba68
"""FastAPI application entry point."""
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
import uvicorn
from .api.routes import router
# Create FastAPI app
app = FastAPI(
title="Package Delivery Search API",
description="Search algorithms for package delivery optimization",
version="1.0.0",
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API routes
app.include_router(router)
# Serve static frontend files
static_dir = Path("/app/frontend/dist")
if static_dir.exists():
# Mount assets directory
app.mount(
"/assets", StaticFiles(directory=str(static_dir / "assets")), name="assets"
)
# Serve index.html for root and all non-API routes
@app.get("/")
async def serve_root():
return FileResponse(str(static_dir / "index.html"))
@app.get("/{full_path:path}")
async def serve_frontend(full_path: str):
# Don't intercept API routes
if full_path.startswith("api/"):
return {"error": "API endpoint not found"}
# Try to serve the requested file
file_path = static_dir / full_path
if file_path.is_file():
return FileResponse(str(file_path))
# Otherwise serve index.html (SPA routing)
return FileResponse(str(static_dir / "index.html"))
else:
@app.get("/")
async def root():
"""Root endpoint."""
return {
"name": "Package Delivery Search API",
"version": "1.0.0",
"endpoints": {
"health": "/api/health",
"algorithms": "/api/algorithms",
"generate": "/api/grid/generate",
"path": "/api/search/path",
"plan": "/api/search/plan",
"compare": "/api/search/compare",
},
}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)