Fix ALLOWED_HOSTS parameter

This commit is contained in:
Romain LEON 2025-03-21 20:40:55 +01:00 committed by GitHub
parent e5400e345b
commit 815ada65b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,7 @@ import re
from os import environ from os import environ
from os.path import abspath, dirname, join from os.path import abspath, dirname, join
from typing import Any, Callable, Tuple from typing import Any, Callable, Tuple
from ast import literal_eval
# For reference see https://docs.netbox.dev/en/stable/configuration/ # For reference see https://docs.netbox.dev/en/stable/configuration/
# Based on https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration_example.py # Based on https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration_example.py
@ -57,7 +58,7 @@ _BASE_DIR = dirname(dirname(abspath(__file__)))
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name. # access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
# #
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local'] # Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
ALLOWED_HOSTS = environ.get('ALLOWED_HOSTS', '*').split(' ') ALLOWED_HOSTS = literal_eval(environ.get('ALLOWED_HOSTS', '*'))
# ensure that '*' or 'localhost' is always in ALLOWED_HOSTS (needed for health checks) # ensure that '*' or 'localhost' is always in ALLOWED_HOSTS (needed for health checks)
if '*' not in ALLOWED_HOSTS and 'localhost' not in ALLOWED_HOSTS: if '*' not in ALLOWED_HOSTS and 'localhost' not in ALLOWED_HOSTS:
ALLOWED_HOSTS.append('localhost') ALLOWED_HOSTS.append('localhost')