From c6d53fe8b10557e58d26558b8ab51dc178aee41a Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Sun, 19 Feb 2023 18:46:52 -0600 Subject: [PATCH] added validator to trim base url trailing slash (#2142) --- mealie/core/settings/settings.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mealie/core/settings/settings.py b/mealie/core/settings/settings.py index f80ed3b8192..e7bcc345ac1 100644 --- a/mealie/core/settings/settings.py +++ b/mealie/core/settings/settings.py @@ -1,7 +1,7 @@ import secrets from pathlib import Path -from pydantic import BaseSettings, NoneStr +from pydantic import BaseSettings, NoneStr, validator from .db_providers import AbstractDBProvider, db_provider_factory @@ -25,12 +25,17 @@ def determine_secrets(data_dir: Path, production: bool) -> str: class AppSettings(BaseSettings): PRODUCTION: bool BASE_URL: str = "http://localhost:8080" + """trailing slashes are trimmed (ex. `http://localhost:8080/` becomes ``http://localhost:8080`)""" + IS_DEMO: bool = False API_PORT: int = 9000 API_DOCS: bool = True - TOKEN_TIME: int = 48 # Time in Hours + TOKEN_TIME: int = 48 + """time in hours""" + SECRET: str - LOG_LEVEL: str = "INFO" # Corresponds to standard Python log levels. + LOG_LEVEL: str = "INFO" + """corresponds to standard Python log levels""" GIT_COMMIT_HASH: str = "unknown" @@ -40,7 +45,15 @@ class AppSettings(BaseSettings): # Security Configuration SECURITY_MAX_LOGIN_ATTEMPTS: int = 5 - SECURITY_USER_LOCKOUT_TIME: int = 24 # Time in Hours + SECURITY_USER_LOCKOUT_TIME: int = 24 + "time in hours" + + @validator("BASE_URL") + def remove_trailing_slash(cls, v: str) -> str: + if v and v[-1] == "/": + return v[:-1] + + return v @property def DOCS_URL(self) -> str | None: