Windows: Fix EOSdash startup Closes #436 #447 (#450)
Some checks failed
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled

* On Windows use 127.0.0.1 as default config host (model defaults) and
   addionally redirect 0.0.0.0 to localhost on Windows (because default
   config file still has 0.0.0.0).
   Use 0.0.0.0 as default otherwise (e.g. Linux/Docker) to allow EOS
   being accessible on local network (not just same host).
   Note: Docs generation on Windows is incompatible with the Github
   pipeline tests. Address this in the nested-config feature branch.
 * Update install/startup instructions as package installation is
   required atm and Docker on Windows has to be accessed at localhost or
   127.0.0.1 even though the server log says 0.0.0.0 (which is required
   to be available outside the container).
 * Fix EOSdash startup with read_only: true (support session key via
   EOS_SERVER__EOSDASH_SESSKEY variable). Backport of feature branch.
 * Remove root_path, causing Windows to fail load swagger UI (/docs).
This commit is contained in:
Dominique Lasserre
2025-02-10 00:38:35 +01:00
committed by GitHub
parent caed880672
commit b380624c9f
8 changed files with 26 additions and 8 deletions

View File

@@ -223,7 +223,6 @@ app = FastAPI(
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
},
lifespan=lifespan,
root_path=str(Path(__file__).parent),
)
@@ -882,9 +881,13 @@ async def proxy_put(request: Request, path: str) -> Response:
async def proxy(request: Request, path: str) -> Union[Response | RedirectResponse | HTMLResponse]:
if config_eos.server_eosdash_host and config_eos.server_eosdash_port:
# Make hostname Windows friendly
host = str(config_eos.server_eosdash_host)
if host == "0.0.0.0" and os.name == "nt":
host = "localhost"
if host and config_eos.server_eosdash_port:
# Proxy to EOSdash server
url = f"http://{config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}/{path}"
url = f"http://{host}:{config_eos.server_eosdash_port}/{path}"
headers = dict(request.headers)
data = await request.body()

View File

@@ -24,7 +24,7 @@ for field_name in config_eos.model_fields:
configs.append(config)
app = FastHTML()
app = FastHTML(secret_key=os.getenv("EOS_SERVER__EOSDASH_SESSKEY"))
rt = app.route

View File

@@ -1,5 +1,6 @@
"""Server Module."""
import os
from typing import Optional
from pydantic import Field, IPvAnyAddress, field_validator
@@ -10,6 +11,12 @@ from akkudoktoreos.core.logging import get_logger
logger = get_logger(__name__)
def get_default_host() -> str:
if os.name == "nt":
return "127.0.0.1"
return "0.0.0.0"
class ServerCommonSettings(SettingsBaseModel):
"""Common server settings.
@@ -18,7 +25,7 @@ class ServerCommonSettings(SettingsBaseModel):
"""
server_eos_host: Optional[IPvAnyAddress] = Field(
default="0.0.0.0", description="EOS server IP address."
default=get_default_host(), description="EOS server IP address."
)
server_eos_port: Optional[int] = Field(default=8503, description="EOS server IP port number.")
server_eos_verbose: Optional[bool] = Field(default=False, description="Enable debug output")
@@ -26,7 +33,7 @@ class ServerCommonSettings(SettingsBaseModel):
default=True, description="EOS server to start EOSdash server."
)
server_eosdash_host: Optional[IPvAnyAddress] = Field(
default="0.0.0.0", description="EOSdash server IP address."
default=get_default_host(), description="EOSdash server IP address."
)
server_eosdash_port: Optional[int] = Field(
default=8504, description="EOSdash server IP port number."