Minor tweaks about non-root handling

main
Thomas Sileo 2022-11-04 19:28:21 +01:00
parent 1c076049cf
commit 540b9d1470
3 changed files with 10 additions and 5 deletions

View File

@ -90,7 +90,6 @@ class Config(pydantic.BaseModel):
name: str name: str
summary: str summary: str
https: bool https: bool
id: str = None
icon_url: str icon_url: str
secret: str secret: str
debug: bool = False debug: bool = False
@ -113,6 +112,9 @@ class Config(pydantic.BaseModel):
sqlalchemy_database: str | None = None sqlalchemy_database: str | None = None
key_path: str | None = None key_path: str | None = None
# Only set when the app is served on a non-root path
id: str | None = None
def load_config() -> Config: def load_config() -> Config:
try: try:
@ -147,6 +149,9 @@ CONFIG = load_config()
DOMAIN = CONFIG.domain DOMAIN = CONFIG.domain
_SCHEME = "https" if CONFIG.https else "http" _SCHEME = "https" if CONFIG.https else "http"
ID = f"{_SCHEME}://{DOMAIN}" ID = f"{_SCHEME}://{DOMAIN}"
# When running the app on a path, the ID maybe set by the config, but in this
# case, a valid webfinger must be served on the root domain
if CONFIG.id: if CONFIG.id:
ID = CONFIG.id ID = CONFIG.id
USERNAME = CONFIG.username USERNAME = CONFIG.username
@ -179,7 +184,9 @@ if CONFIG.emoji:
EMOJIS = CONFIG.emoji EMOJIS = CONFIG.emoji
# Emoji template for the FE # Emoji template for the FE
EMOJI_TPL = '<img src="{base_url}/static/twemoji/{filename}.svg" alt="{raw}" class="emoji">' EMOJI_TPL = (
'<img src="{base_url}/static/twemoji/{filename}.svg" alt="{raw}" class="emoji">'
)
_load_emojis(ROOT_DIR, BASE_URL) _load_emojis(ROOT_DIR, BASE_URL)

View File

@ -7,7 +7,7 @@
{% if error %} {% if error %}
<p class="primary-color">Invalid password.</p> <p class="primary-color">Invalid password.</p>
{% endif %} {% endif %}
<form class="form" method="POST"> <form class="form" action="{{ BASE_URL }}/admin/login" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}"> <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="hidden" name="redirect" value="{{ redirect }}"> <input type="hidden" name="redirect" value="{{ redirect }}">
<input type="password" placeholder="password" name="password" autofocus> <input type="password" placeholder="password" name="password" autofocus>

View File

@ -74,8 +74,6 @@ def main() -> None:
dat["https"] = False dat["https"] = False
proto = "http" proto = "http"
dat["id"] = f'{proto}://{dat["domain"]}'
print("Note that you can put your icon/avatar in the static/ directory") print("Note that you can put your icon/avatar in the static/ directory")
dat["icon_url"] = prompt( dat["icon_url"] = prompt(
"icon URL: ", default=f'{proto}://{dat["domain"]}/static/nopic.png' "icon URL: ", default=f'{proto}://{dat["domain"]}/static/nopic.png'