rewrites web server to hot-reload the web settings from the settings file

This commit is contained in:
Mose Müller 2023-12-21 10:32:37 +01:00
parent ef36c01407
commit 6543bc6b39

View File

@ -106,7 +106,6 @@ class WebServer:
def _initialise_configuration(self) -> None: def _initialise_configuration(self) -> None:
logger.debug("Initialising web server configuration...") logger.debug("Initialising web server configuration...")
self.web_settings = {}
file_path = self._service_config_dir / "web_settings.json" file_path = self._service_config_dir / "web_settings.json"
if self._generate_new_web_settings: if self._generate_new_web_settings:
@ -119,15 +118,6 @@ class WebServer:
json.dumps(self._generated_web_settings_dict(), indent=4) json.dumps(self._generated_web_settings_dict(), indent=4)
) )
# File exists, read and return its content
if file_path.exists():
logger.debug(
"Reading configuration from file '%s' ...", file_path.absolute()
)
with file_path.open("r", encoding="utf-8") as file:
self.web_settings = json.load(file)
def _generated_web_settings_dict(self) -> dict[str, dict[str, Any]]: def _generated_web_settings_dict(self) -> dict[str, dict[str, Any]]:
return { return {
path: {"displayName": path.split(".")[-1], "index": i} path: {"displayName": path.split(".")[-1], "index": i}
@ -167,7 +157,19 @@ class WebServer:
@app.get("/web-settings") @app.get("/web-settings")
def web_settings() -> dict[str, Any]: def web_settings() -> dict[str, Any]:
return self.web_settings file_path = self._service_config_dir / "web_settings.json"
web_settings = {}
# File exists, read its content
if file_path.exists():
logger.debug(
"Reading configuration from file '%s' ...", file_path.absolute()
)
with file_path.open("r", encoding="utf-8") as file:
web_settings = json.load(file)
return web_settings
# exposing custom.css file provided by user # exposing custom.css file provided by user
if self.css is not None: if self.css is not None: