- Fix API routing: redirect_slashes=False + strip trailing slashes from route paths - Fix StaticFiles catch-all intercepting /api/* before FastAPI redirect - Add [tool.hatch.build.targets.wheel] to pyproject.toml for Docker builds - Install docker-compose plugin (v2.34.0) as CLI plugin - Create Dockerfile (python:3.11-alpine, CMD python -m lightsync) - Create docker-compose.prod.yml (Traefik + Authelia, edge network) - Deploy lightsync container to lightsync.groll.cloud - Add LightSync entry to start/projects.json - Update frontend app.js to use /api/devices (no trailing slash)
25 lines
704 B
Python
25 lines
704 B
Python
from fastapi import APIRouter, HTTPException
|
|
from lightsync.models.device import DeviceConfig
|
|
import lightsync.main as state # access registry via module-level ref
|
|
|
|
router = APIRouter(tags=["devices"])
|
|
|
|
|
|
@router.get("")
|
|
async def list_devices() -> list[DeviceConfig]:
|
|
return state.registry.list_all()
|
|
|
|
|
|
@router.post("", status_code=201)
|
|
async def add_device(config: DeviceConfig) -> DeviceConfig:
|
|
state.registry.add(config)
|
|
await state.registry.save()
|
|
return config
|
|
|
|
|
|
@router.delete("/{device_id}", status_code=204)
|
|
async def remove_device(device_id: str):
|
|
if not state.registry.remove(device_id):
|
|
raise HTTPException(404, "Device not found")
|
|
await state.registry.save()
|