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

2
.gitignore vendored
View File

@@ -199,7 +199,7 @@ cython_debug/
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
.vscode/
# Ruff stuff:
.ruff_cache/

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

View File

@@ -1,6 +1,6 @@
from fastapi.routing import APIRouter
from control_backend.api.v1.endpoints import message, sse
from control_backend.api.v1.endpoints import message, sse, sse_ping
api_router = APIRouter()
@@ -13,3 +13,8 @@ api_router.include_router(
sse.router,
tags=["SSE"]
)
api_router.include_router(
sse_ping.router,
tags=["SSE_ping"]
)