fix: gitignore + testing map structure

ref: N25B-205
This commit is contained in:
Björn Otgaar
2025-10-22 12:41:47 +02:00
parent 77c6704632
commit d71cb60523
5 changed files with 33 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
from fastapi import APIRouter, Request
from fastapi.responses import StreamingResponse
import datetime
import asyncio
router = APIRouter()
@router.get("/sse_ping")
async def sse_ping(request: Request):
"""
Endpoint for Server-Sent Events.
"""
async def event_generator():
while True:
# If connection to client closes, stop sending events
if await request.is_disconnected():
break
# Send message containing current time every second
current_time = datetime.datetime.now().strftime("%H:%M:%S")
yield f"data: Server time: {current_time}\n\n" # \n\n is needed to separate events (SSE is text-based)
await asyncio.sleep(1)
return StreamingResponse(event_generator(), media_type="text/event-stream") # media_type specifies that this connection is for event streams