Fixed https url-reversing issue in development
This commit is contained in:
parent
b69d9f221b
commit
81e7b900fe
3
.env.dev
3
.env.dev
|
@ -12,3 +12,6 @@ MUSIC_DIRECTORY_PATH=/music
|
||||||
BROWSABLE_API_ENABLED=True
|
BROWSABLE_API_ENABLED=True
|
||||||
FORWARDED_PROTO=http
|
FORWARDED_PROTO=http
|
||||||
LDAP_ENABLED=False
|
LDAP_ENABLED=False
|
||||||
|
|
||||||
|
# Uncomment this if you're using traefik/https
|
||||||
|
# FORCE_HTTPS_URLS=True
|
||||||
|
|
|
@ -14,6 +14,7 @@ from .common import * # noqa
|
||||||
# DEBUG
|
# DEBUG
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
DEBUG = env.bool("DJANGO_DEBUG", default=True)
|
DEBUG = env.bool("DJANGO_DEBUG", default=True)
|
||||||
|
FORCE_HTTPS_URLS = env.bool("FORCE_HTTPS_URLS", default=False)
|
||||||
TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG
|
TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG
|
||||||
|
|
||||||
# SECRET CONFIGURATION
|
# SECRET CONFIGURATION
|
||||||
|
@ -80,3 +81,5 @@ CSRF_TRUSTED_ORIGINS = [o for o in ALLOWED_HOSTS]
|
||||||
if env.bool("WEAK_PASSWORDS", default=False):
|
if env.bool("WEAK_PASSWORDS", default=False):
|
||||||
# Faster during tests
|
# Faster during tests
|
||||||
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
|
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
|
||||||
|
|
||||||
|
MIDDLEWARE = ("funkwhale_api.common.middleware.DevHttpsMiddleware",) + MIDDLEWARE
|
||||||
|
|
|
@ -135,3 +135,25 @@ class SPAFallbackMiddleware:
|
||||||
return serve_spa(request)
|
return serve_spa(request)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class DevHttpsMiddleware:
|
||||||
|
"""
|
||||||
|
In development, it's sometimes difficult to have django use HTTPS
|
||||||
|
when we have django behind nginx behind traefix.
|
||||||
|
|
||||||
|
We thus use a simple setting (in dev ONLY) to control that.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, get_response):
|
||||||
|
self.get_response = get_response
|
||||||
|
|
||||||
|
def __call__(self, request):
|
||||||
|
if settings.FORCE_HTTPS_URLS:
|
||||||
|
setattr(request.__class__, "scheme", "https")
|
||||||
|
setattr(
|
||||||
|
request,
|
||||||
|
"get_host",
|
||||||
|
lambda: request.__class__.get_host(request).replace(":80", ":443"),
|
||||||
|
)
|
||||||
|
return self.get_response(request)
|
||||||
|
|
Loading…
Reference in New Issue