59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import os
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import FileResponse
|
|
|
|
from app.core.config import settings
|
|
from app.core.database import connect_to_mongo, close_mongo_connection
|
|
from app.api.routes import health, projects
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await connect_to_mongo()
|
|
yield
|
|
await close_mongo_connection()
|
|
|
|
|
|
app = FastAPI(
|
|
title="RFCP Backend API",
|
|
description="RF Coverage Planning Backend",
|
|
version="1.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# CORS for frontend
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["https://rfcp.eliah.one", "http://localhost:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Routes
|
|
app.include_router(health.router, prefix="/api/health", tags=["health"])
|
|
app.include_router(projects.router, prefix="/api/projects", tags=["projects"])
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "RFCP Backend API", "version": "1.1.0"}
|
|
|
|
|
|
@app.get("/api/terrain/{region}")
|
|
async def get_terrain(region: str):
|
|
"""Serve SRTM terrain .hgt files."""
|
|
terrain_path = os.path.join(settings.TERRAIN_DATA_DIR, f"{region}.hgt")
|
|
if os.path.exists(terrain_path):
|
|
return FileResponse(terrain_path)
|
|
return {"error": "Region not found"}, 404
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8090)
|