Fix runtime config update by Server Options panel.
This commit is contained in:
@@ -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."""
|
"""Update the stored configuration."""
|
||||||
with _db.transaction("update_config"):
|
with _db.transaction("update_config"):
|
||||||
_db.config = config
|
_db.config = config
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from paskia.fastapi.session import AUTH_COOKIE
|
|||||||
from paskia.globals import passkey
|
from paskia.globals import passkey
|
||||||
from paskia.sansio import Passkey
|
from paskia.sansio import Passkey
|
||||||
from paskia.util import hostutil
|
from paskia.util import hostutil
|
||||||
|
from paskia.util.runtime import update_runtime_config
|
||||||
|
|
||||||
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
|
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
|
||||||
|
|
||||||
@@ -79,9 +80,6 @@ async def admin_update_server_config(
|
|||||||
origins=origins,
|
origins=origins,
|
||||||
listen=config.listen,
|
listen=config.listen,
|
||||||
)
|
)
|
||||||
await db.update_config(new_config)
|
db.update_config(new_config)
|
||||||
|
update_runtime_config(new_config)
|
||||||
# Reload hostutil cached config so auth_host changes take effect
|
|
||||||
hostutil.reload_config()
|
|
||||||
|
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|||||||
@@ -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
|
# Bootstrap and persist config now that the full DB is loaded
|
||||||
await bootstrap_if_needed(config=runtime.config)
|
await bootstrap_if_needed(config=runtime.config)
|
||||||
if runtime.save:
|
if runtime.save:
|
||||||
await db.update_config(runtime.config)
|
db.update_config(runtime.config)
|
||||||
await flush()
|
await flush()
|
||||||
|
|
||||||
# Restore uvicorn info logging (suppressed during startup in dev mode)
|
# Restore uvicorn info logging (suppressed during startup in dev mode)
|
||||||
|
|||||||
@@ -29,3 +29,31 @@ def _load_config() -> "RuntimeConfig | None":
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
return msgspec.json.decode(config_json.encode(), type=RuntimeConfig)
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user