Harmonize 'localhost' v.s. '127.0.0.1' defaults

* The default is "localhost" now (as per what we write in the docs on the
  website). (It already was the default for Docker, but not for all settings
  yet)
* FREE_VERSION-nagging adapted accordingly
* create_conf: adapted accordingly.
* create_conf: Fix help-text ("BASE_URL" not "SITE_TITLE")
* deduce_allowed_hosts
    * don't just generally accept "*" for the locally hosted one, instead
      specify the 2 correct spellings
    * "and vice versa" ("localhost" accepted in your browser bar if you specify 127.0.0.1)
This commit is contained in:
Klaas van Schelven
2024-11-18 13:36:53 +01:00
parent c68563f11e
commit 8ff309cd8f
4 changed files with 8 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ _PORT = os.environ.get("PORT", "8000")
DEFAULTS = {
"BASE_URL": f"http://127.0.0.1:{_PORT}", # no trailing slash
"BASE_URL": f"http://localhost:{_PORT}", # no trailing slash
"SITE_TITLE": "Bugsink", # you can customize this as e.g. "My Bugsink" or "Bugsink for My Company"
# Users, teams, projects

View File

@@ -70,7 +70,7 @@ def useful_settings_processor(request):
# (First version of "should I nag" logic): nag only after considerable time to play with the app, and for "some
# indication" that you're using this in production (the simplest such indication is that you've configured a
# BASE_URL that's not localhost). Subject to change.
system_warnings = [FREE_VERSION_WARNING] if nag_30 and '127.0.0.1' not in get_settings().BASE_URL else []
system_warnings = [FREE_VERSION_WARNING] if nag_30 and 'localhost' not in get_settings().BASE_URL else []
return {
# Note: no way to actually set the license key yet, so nagging always happens for now.

View File

@@ -13,8 +13,8 @@ def main():
"--template", help="Template to use; recommended or local", choices=["recommended", "local", "docker"],
required=True)
parser.add_argument("--port", help="Port to use in SITE_TITLE ; default is 8000", type=int, default=8000)
parser.add_argument("--host", help="Host to use in SITE_TITLE ; default is 127.0.0.1", default="127.0.0.1")
parser.add_argument("--port", help="Port to use in BASE_URL ; default is 8000", type=int, default=8000)
parser.add_argument("--host", help="Host to use in BASE_URL ; default is localhost", default="localhost")
parser.add_argument(
"--base-dir", help="base dir for databases, snappea, and ingestion store ('recommended' template only)",
default="/home/bugsink")

View File

@@ -26,8 +26,8 @@ def send_rendered_email(subject, base_template_name, recipient_list, context=Non
def deduce_allowed_hosts(base_url):
url = urlparse(base_url)
if url.hostname == "localhost":
# Allow all hosts when running locally; useful to avoid understanding why 127.0.0.1:8000 is not allowed when
# localhost:8000 is.
return ["*"]
if url.hostname == "localhost" or url.hostname == "127.0.0.1":
# Allow both 127.0.0.1 and localhost as hostname when running locally; useful to avoid understanding why
# localhost:8000 is not allowed when 127.0.0.1:8000 is and vice versa.
return ["localhost", "127.0.0.1"]
return [url.hostname]