Added support for multiple hosts in caddy configuration and CSRF_TRUSTED_ORIGINS #22

This commit is contained in:
ChaoticByte 2023-02-12 10:59:22 +01:00
parent b78e196fec
commit fb3bbf3fc5
4 changed files with 13 additions and 8 deletions

View file

@ -7,7 +7,7 @@
https_port {$HTTPS_PORT} https_port {$HTTPS_PORT}
} }
{$CADDY_HOST} { {$CADDY_HOSTS} {
# the tls certificates # the tls certificates
tls {$DATADIR}/tls/server.pem {$DATADIR}/tls/server-key.pem tls {$DATADIR}/tls/server.pem {$DATADIR}/tls/server-key.pem
route { route {

View file

@ -28,7 +28,9 @@ db:
port: 5432 port: 5432
caddy: caddy:
# Webserver settings # Webserver settings
host: "localhost" hosts:
- "localhost"
- "127.0.0.1"
http_port: 80 http_port: 80
https_port: 443 https_port: 443
logs: logs:

View file

@ -125,11 +125,13 @@ AUTH_USER_MODEL = "app.User"
SESSION_COOKIE_AGE = int(config["app"]["session_cookie_age"]) SESSION_COOKIE_AGE = int(config["app"]["session_cookie_age"])
CSRF_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True
CSRF_TRUSTED_ORIGINS = [ CSRF_TRUSTED_ORIGINS = []
f"https://{config['caddy']['host']}",
f"http://{config['caddy']['host']}", for host in config['caddy']['hosts']:
f"https://{config['caddy']['host']}:{config['caddy']['https_port']}", CSRF_TRUSTED_ORIGINS.append(f"http://{host}")
f"http://{config['caddy']['host']}:{config['caddy']['https_port']}"] CSRF_TRUSTED_ORIGINS.append(f"https://{host}")
CSRF_TRUSTED_ORIGINS.append(f"http://{host}:{config['caddy']['https_port']}")
CSRF_TRUSTED_ORIGINS.append(f"https://{host}:{config['caddy']['https_port']}")
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/

View file

@ -118,7 +118,8 @@ if __name__ == "__main__":
# Caddy configuration via env # Caddy configuration via env
environment_caddy = os.environ environment_caddy = os.environ
environment_caddy["DATADIR"] = str(data_directory.absolute()) environment_caddy["DATADIR"] = str(data_directory.absolute())
environment_caddy["CADDY_HOST"] = str(config["caddy"]["host"]) environment_caddy["CADDY_HOSTS"] = ", ".join(config["caddy"]["hosts"])
print(environment_caddy["CADDY_HOSTS"])
environment_caddy["HTTP_PORT"] = str(config["caddy"]["http_port"]) environment_caddy["HTTP_PORT"] = str(config["caddy"]["http_port"])
environment_caddy["HTTPS_PORT"] = str(config["caddy"]["https_port"]) environment_caddy["HTTPS_PORT"] = str(config["caddy"]["https_port"])
environment_caddy["APPLICATION_PORT"] = str(config["app"]["application_port"]) environment_caddy["APPLICATION_PORT"] = str(config["app"]["application_port"])