mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
Proxy handling #131
This commit is contained in:
parent
48cbc4e8cd
commit
f77b7de90c
@ -29,6 +29,14 @@ app.config["SECURITY_EMAIL_SENDER"] = os.getenv("MAIL_DEFAULT_SENDER")
|
||||
app.config["LANGUAGES"] = ["en", "de"]
|
||||
app.config["SERVER_NAME"] = os.getenv("SERVER_NAME")
|
||||
|
||||
# Proxy handling
|
||||
if os.getenv("PREFERRED_URL_SCHEME"): # pragma: no cover
|
||||
app.config["PREFERRED_URL_SCHEME"] = os.getenv("PREFERRED_URL_SCHEME")
|
||||
|
||||
from project.reverse_proxied import ReverseProxied
|
||||
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
|
||||
# Generate a nice key using secrets.token_urlsafe()
|
||||
app.config["SECRET_KEY"] = os.environ.get(
|
||||
"SECRET_KEY", "pf9Wkove4IKEAXvy-cQkeDPhv9Cb3Ag-wyJILbq_dFw"
|
||||
|
||||
14
project/reverse_proxied.py
Normal file
14
project/reverse_proxied.py
Normal file
@ -0,0 +1,14 @@
|
||||
from project import app
|
||||
|
||||
|
||||
class ReverseProxied(object):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
# if one of x_forwarded or preferred_url is https, prefer it.
|
||||
forwarded_scheme = environ.get("HTTP_X_FORWARDED_PROTO", None)
|
||||
preferred_scheme = app.config.get("PREFERRED_URL_SCHEME", None)
|
||||
if "https" in [forwarded_scheme, preferred_scheme]: # pragma: no cover
|
||||
environ["wsgi.url_scheme"] = "https"
|
||||
return self.app(environ, start_response)
|
||||
Loading…
x
Reference in New Issue
Block a user