Fix runtime config update by Server Options panel.

This commit is contained in:
2026-02-19 19:57:12 +00:00
parent 3cb24bfee9
commit dd2031eef5
4 changed files with 33 additions and 7 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ def is_username_taken(username: str, exclude_uuid: UUID | None = None) -> bool:
# -------------------------------------------------------------------------
async def update_config(config: Config) -> None:
def update_config(config: Config) -> None:
"""Update the stored configuration."""
with _db.transaction("update_config"):
_db.config = config
+3 -5
View File
@@ -8,6 +8,7 @@ from paskia.fastapi.session import AUTH_COOKIE
from paskia.globals import passkey
from paskia.sansio import Passkey
from paskia.util import hostutil
from paskia.util.runtime import update_runtime_config
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
@@ -79,9 +80,6 @@ async def admin_update_server_config(
origins=origins,
listen=config.listen,
)
await db.update_config(new_config)
# Reload hostutil cached config so auth_host changes take effect
hostutil.reload_config()
db.update_config(new_config)
update_runtime_config(new_config)
return {"status": "ok"}
+1 -1
View File
@@ -57,7 +57,7 @@ async def lifespan(app: FastAPI): # pragma: no cover - startup path
# Bootstrap and persist config now that the full DB is loaded
await bootstrap_if_needed(config=runtime.config)
if runtime.save:
await db.update_config(runtime.config)
db.update_config(runtime.config)
await flush()
# Restore uvicorn info logging (suppressed during startup in dev mode)
+28
View File
@@ -29,3 +29,31 @@ def _load_config() -> "RuntimeConfig | None":
return None
return msgspec.json.decode(config_json.encode(), type=RuntimeConfig)
def update_runtime_config(new_config: Config) -> None:
"""Update the runtime configuration with a new Config and refresh the cache."""
current_runtime = _load_config()
if not current_runtime:
return # No runtime config to update
# Recompute site_url and site_path based on new config
site_path = "/" if new_config.auth_host else "/auth/"
if new_config.auth_host:
site_url = new_config.auth_host
elif new_config.origins:
site_url = new_config.origins[0]
else:
# Keep current site_url if no auth_host and no origins
site_url = current_runtime.site_url
new_runtime = RuntimeConfig(
config=new_config,
site_url=site_url,
site_path=site_path,
save=current_runtime.save,
)
os.environ["PASKIA_CONFIG"] = msgspec.json.encode(new_runtime).decode()
# Clear the cache so next access loads the updated config
_load_config.cache_clear()