|
15 | 15 |
|
16 | 16 | import json |
17 | 17 |
|
| 18 | +from werkzeug.middleware.proxy_fix import ProxyFix |
| 19 | + |
18 | 20 | # import re |
19 | 21 | from pathlib import Path |
20 | 22 | from pkg_resources import iter_entry_points |
|
67 | 69 |
|
68 | 70 | ########################################################################################### |
69 | 71 |
|
70 | | - |
71 | | -class ReverseProxied(object): |
72 | | - def __init__(self, app_in, script_name=None, scheme=None, server=None): |
73 | | - self.app = app_in |
74 | | - self.script_name = script_name |
75 | | - self.scheme = scheme |
76 | | - self.server = server |
77 | | - |
78 | | - def __call__(self, environ, start_response): |
79 | | - script_name = environ.get("HTTP_X_SCRIPT_NAME", "") or self.script_name |
80 | | - if script_name: |
81 | | - environ["SCRIPT_NAME"] = script_name |
82 | | - path_info = environ["PATH_INFO"] |
83 | | - if path_info.startswith(script_name): |
84 | | - environ["PATH_INFO"] = path_info[len(script_name) :] |
85 | | - scheme = environ.get("HTTP_X_SCHEME", "") or self.scheme |
86 | | - if scheme: |
87 | | - environ["wsgi.url_scheme"] = scheme |
88 | | - server = environ.get("HTTP_X_FORWARDED_SERVER", "") or self.server |
89 | | - if server: |
90 | | - environ["HTTP_HOST"] = server |
91 | | - return self.app(environ, start_response) |
92 | | - |
93 | | - |
94 | 72 | # initiation du framework flask |
95 | 73 | app = Flask(__name__, template_folder="oeasc/templates", static_folder="../static") |
96 | 74 |
|
97 | | - |
98 | 75 | # cors permet de gérer les requetes venant d'autres domaines. * signifie que tout le monde peut se connecter |
99 | 76 | cors = CORS(app, resources={r"*": {"origins": "*"}}, supports_credentials=True) |
100 | 77 |
|
101 | | -# app.wsgi_app = ReverseProxied(app.wsgi_app) |
| 78 | + |
| 79 | +app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1, x_prefix=1) |
| 80 | + |
102 | 81 |
|
103 | 82 | # intégration des données de configuration dans l'application. Mettre silent=True en production |
104 | 83 | if ( |
@@ -148,8 +127,6 @@ def __call__(self, environ, start_response): |
148 | 127 | app.config["MAIL"] = mail |
149 | 128 | # initialisation des parametres de mails. Récupère les paramètres dans config.py via app.config |
150 | 129 | mail.init_app(app) |
151 | | -# ajoute l'instance mail à la configuration de l'application pour y acceder facilement |
152 | | -app.config["MAIL"] = mail |
153 | 130 |
|
154 | 131 | # pour signer les cookies de session et proteger contre les attaques CSRF |
155 | 132 | # inutile c'est déja déclaré dans app.config.from_pyfile("../config/config.py", silent=True) |
|
0 commit comments