Initial scaffold: React+TS+Vite frontend, FastAPI backend, config system
This commit is contained in:
0
backend/routes/__init__.py
Normal file
0
backend/routes/__init__.py
Normal file
31
backend/routes/config_routes.py
Normal file
31
backend/routes/config_routes.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from fastapi import APIRouter
|
||||
from config import get_config, save_config, load_config, AppConfig
|
||||
|
||||
router = APIRouter(prefix="/api")
|
||||
|
||||
|
||||
@router.get("/config")
|
||||
async def get_configuration():
|
||||
config = get_config()
|
||||
return config.model_dump()
|
||||
|
||||
|
||||
@router.put("/config")
|
||||
async def update_configuration(data: AppConfig):
|
||||
save_config(data)
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@router.post("/config/reload")
|
||||
async def reload_configuration():
|
||||
load_config()
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health_check():
|
||||
from mqtt_bridge import get_mqtt_status
|
||||
return {
|
||||
"status": "ok",
|
||||
"mqtt": get_mqtt_status(),
|
||||
}
|
||||
19
backend/routes/ws_routes.py
Normal file
19
backend/routes/ws_routes.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
||||
from mqtt_bridge import register_ws_client, unregister_ws_client
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.websocket("/api/ws/events")
|
||||
async def websocket_events(ws: WebSocket):
|
||||
await ws.accept()
|
||||
register_ws_client(ws)
|
||||
try:
|
||||
while True:
|
||||
# Keep connection alive, handle client messages if needed
|
||||
data = await ws.receive_text()
|
||||
# Client can send ping/keepalive
|
||||
except WebSocketDisconnect:
|
||||
pass
|
||||
finally:
|
||||
unregister_ws_client(ws)
|
||||
Reference in New Issue
Block a user