Server: basic implementation. Not tested => no python installed; bugfix in ESP (uvicorn on port 8090)

This commit is contained in:
Thomas Karner committed 2026-09-20 23:49:40 +02:00
1 parent 3694cdf207
commit 8a51e3d95e
38 files changed
+2442 -21

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
from __future__ import annotations
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from .. import __version__
from ..config import get_settings
from ..logging_setup import configure_logging
from .routes import health
log = logging.getLogger(__name__)
API_PREFIX = "/api/v1"
@asynccontextmanager
async def lifespan(app: FastAPI):
settings = get_settings()
log.info(
"poorbird api starting",
extra={"version": __version__, "image_root": str(settings.image_root)},
)
if not settings.enroll_secret_is_set:
# Not fatal at Phase 1 -- no device endpoint exists yet -- but it will
# be the first thing to break in Phase 2.
log.warning("POORBIRD_ENROLL_SECRET is not set; device enrollment will refuse requests")
yield
log.info("poorbird api stopping")
def create_app() -> FastAPI:
settings = get_settings()
configure_logging(settings.log_level, settings.log_format)
app = FastAPI(
title="poorBird",
version=__version__,
summary="Ingest, gallery and device management for a radar-triggered bird camera",
lifespan=lifespan,
)
app.include_router(health.router, prefix=API_PREFIX, tags=["health"])
app.include_router(health.root_router)
# Phase 2 mounts the device endpoints here: /enroll, /ingest, /heartbeat,
# /status, /config, /commands/{id}/ack, /firmware/{version}.bin.
# Phase 3 mounts the UI endpoints. See firmware/API.md for the contract.
return app
app = create_app()