Bobby Noelte 34d8e88771
Rename FastAPI server to EOS. (#355)
Rename FastAPI server to `eos` and FastHTML server to `eosdash`.

Make an user easily identify what server is meant. FastAPI and FastHTML are
implementation details that may confuse the non-technical user.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2025-01-09 16:54:49 +01:00

59 lines
1.6 KiB
Python

import uvicorn
from fasthtml.common import H1, FastHTML, Table, Td, Th, Thead, Titled, Tr
from akkudoktoreos.config.config import get_config
from akkudoktoreos.core.logging import get_logger
logger = get_logger(__name__)
config_eos = get_config()
configs = []
for field_name in config_eos.model_fields:
config = {}
config["name"] = field_name
config["value"] = getattr(config_eos, field_name)
config["default"] = config_eos.model_fields[field_name].default
config["description"] = config_eos.model_fields[field_name].description
configs.append(config)
app = FastHTML()
rt = app.route
def config_table() -> Table:
rows = [
Tr(
Td(config["name"]),
Td(config["value"]),
Td(config["default"]),
Td(config["description"]),
cls="even:bg-purple/5",
)
for config in configs
]
flds = "Name", "Value", "Default", "Description"
head = Thead(*map(Th, flds), cls="bg-purple/10")
return Table(head, *rows, cls="w-full")
@rt("/")
def get(): # type: ignore
return Titled("EOS Dashboard", H1("Configuration"), config_table())
if __name__ == "__main__":
try:
logger.info(f"Starting {config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}.")
uvicorn.run(
app, host=str(config_eos.server_eosdash_host), port=config_eos.server_eosdash_port
)
except Exception as e:
# Error handling for binding issues
logger.error(
f"Could not bind to host {config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}. Error: {e}"
)
exit(1)