labthings_fastapi.server.fallback
A fallback server for LabThings.
If the fallback option is given when labthings-server is run, we will
still start an HTTP server even if we cannot run LabThings with the specified
configuration. This means that something will still be viewable at the
expected URL, which is helpful if LabThings is running as a service, or
on embedded hardware.
Attributes
Classes
A basic FastAPI application to serve a LabThings error page. |
Functions
|
Display the LabThings error page. |
|
Redirect all paths on the server to the error page. |
Module Contents
- class labthings_fastapi.server.fallback.FallbackApp(*args: Any, **kwargs: Any)
Bases:
fastapi.FastAPIA basic FastAPI application to serve a LabThings error page.
Set up a simple error server.
This app is used to display a single page, which explains why the LabThings server cannot start.
- Parameters:
*args – is passed to
fastapi.FastAPI.__init__.**kwargs – is passed to
fastapi.FastAPI.__init__.
- labthings_error: BaseException | None = None
- log_history = None
- html_code = 500
- labthings_fastapi.server.fallback.app
- labthings_fastapi.server.fallback.ERROR_PAGE = Multiline-String
Show Value
""" <!DOCTYPE html> <html> <head lang="en"> <title>LabThings</title> <style> pre { white-space: pre-wrap; overflow-wrap: anywhere; } </style> </head> <body> <h1>LabThings Couldn't Load</h1> <p>Something went wrong when setting up your LabThings server.</p> <p>Please check your configuration and try again.</p> <p>More details may be shown below:</p> <pre>{{error}}</pre> <p>The following Things loaded successfully:</p> <ul> {{things}} </ul> <p>Your configuration:</p> <pre>{{config}}</pre> <p>Traceback</p> <pre>{{traceback}}</pre> {{logginginfo}} </body> </html> """
- async labthings_fastapi.server.fallback.root() fastapi.responses.HTMLResponse
Display the LabThings error page.
- Returns:
a response that serves the error as an HTML page.
- async labthings_fastapi.server.fallback.redirect_to_root(path: str) starlette.responses.RedirectResponse
Redirect all paths on the server to the error page.
If any URL other than the error page is requested, this server will redirect it to the error page.
- Parameters:
path – The path requested.
- Returns:
a response redirecting to the error page.