summit/backend/app/main.py

54 lines
1.5 KiB
Python

import sys
import os
# Add the project root directory to python path to allow relative imports
# when running this file directly. This points to the 'backend' directory.
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import settings
from app.api import peaks, routes
import uvicorn
app = FastAPI(
title=settings.PROJECT_NAME,
openapi_url=f"{settings.API_V1_STR}/openapi.json"
)
# CORS
if settings.BACKEND_CORS_ORIGINS:
app.add_middleware(
CORSMiddleware,
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Static Files
app.mount(settings.STATIC_URL_PREFIX, StaticFiles(directory=settings.UPLOAD_DIR), name="static")
# Include Routers
app.include_router(peaks.router, prefix=f"{settings.API_V1_STR}/peaks", tags=["peaks"])
app.include_router(routes.router, prefix=f"{settings.API_V1_STR}/routes", tags=["routes"])
@app.get("/")
async def root():
return {"message": "Welcome to Summit 14 Peaks API"}
@app.get("/health")
async def health_check():
return {"status": "ok"}
if __name__ == "__main__":
# When running directly, we use uvicorn.run
# reload=True enables hot reloading for development
uvicorn.run(
"app.main:app",
host="0.0.0.0",
port=settings.PORT,
reload=True
)