Merge branch 'test-server-startup' into 'v3'

Test server startup

See merge request openflexure/openflexure-microscope-server!379
This commit is contained in:
Julian Stirling 2025-08-27 16:11:34 +00:00
commit 2325dced5e
5 changed files with 318 additions and 26 deletions

View file

@ -4,8 +4,20 @@ import labthings_fastapi as lt
from fastapi import Response
from socket import gethostname
FAKE_ROUTES = [
"/api/v2/",
"/api/v2/streams/snapshot",
"/api/v2/instrument/settings/name",
]
def add_v2_endpoints(thing_server: lt.ThingServer):
class JPEGResponse(Response):
"""A FastAPI response with media_type set for a JPEG image."""
media_type = "image/jpeg"
def add_v2_endpoints(thing_server: lt.ThingServer) -> None:
"""Add the v2 API endpoints for OpenFlexure Connect discoverability."""
app = thing_server.app
@ -19,15 +31,7 @@ def add_v2_endpoints(thing_server: lt.ThingServer):
This is used by OF Connect to identify the microscope.
"""
fake_routes = [
"/api/v2/",
"/api/v2/streams/snapshot",
"/api/v2/instrument/settings/name",
]
return {url: {"url": url, "methods": ["GET"]} for url in fake_routes}
class JPEGResponse(Response):
media_type = "image/jpeg"
return {url: {"url": url, "methods": ["GET"]} for url in FAKE_ROUTES}
@app.get("/api/v2/streams/snapshot")
@app.head("/api/v2/streams/snapshot")