diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-12-05 23:02:49 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-12-05 23:02:49 +0100 |
commit | 6d6b403032a8768c63b4105e592116244b614954 (patch) | |
tree | 4dc286a48e2c8b017b9935c2c204a5807fd66b7b /src | |
parent | 98fc40d3c0a94e0f9cab6c793b2430c7e5bc0f1a (diff) |
add reverse proxy support
use correct version attribute
removed some non-localized urls
allow loading custom config file
Diffstat (limited to 'src')
-rw-r--r-- | src/jwebmail/__init__.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 405f35e..26d6ffc 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -3,6 +3,7 @@ import pwd import sys from os import environ +from werkzeug.middleware.proxy_fix import ProxyFix from flask import Flask, g from flask_babel import Babel, get_locale from flask_login import LoginManager, login_required @@ -54,7 +55,15 @@ def create_app(): app = Flask(__name__) app.jinja_options = dict(undefined=ChainableUndefined) - app.config.from_file("../../jwebmail.toml", load=toml_load, text=False) + if app.config["DEBUG"]: + app.config.from_file("../../jwebmail.toml", load=toml_load, text=False) + else: + print(environ["JWEBMAIL_CONFIG"]) + app.config.from_file(environ["JWEBMAIL_CONFIG"], load=toml_load, text=False) + + if app.config["JWEBMAIL"]["PROXY"]: + app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1) + validate_config(app) DEFAULT_LANGUAGE = app.config["JWEBMAIL"]["DEFAULT_LANGUAGE"] @@ -73,7 +82,7 @@ def create_app(): @app.context_processor def inject_version(): - return {"version": "4.0", "get_locale": get_locale, "format_mail": format_mail} + return {"version": __version__, "get_locale": get_locale, "format_mail": format_mail} @app.url_defaults def add_language_code(endpoint, values): @@ -98,18 +107,13 @@ def route(app): app.add_url_rule("/about", view_func=about) app.add_url_rule("/<lang_code>/about", view_func=about) - app.add_url_rule("/logout", view_func=logout) app.add_url_rule("/<lang_code>/logout", view_func=logout) dh = login_required(displayheaders) - app.add_url_rule("/home/", view_func=dh) - app.add_url_rule("/home/<folder>", view_func=dh) app.add_url_rule("/<lang_code>/home/", view_func=dh) app.add_url_rule("/<lang_code>/home/<folder>", view_func=dh) lr_readmail = login_required(readmail) - app.add_url_rule("/read/<msgid>", endpoint="read", view_func=lr_readmail) - app.add_url_rule("/read/<folder>/<msgid>", endpoint="read", view_func=lr_readmail) app.add_url_rule( "/<lang_code>/read/<msgid>", endpoint="read", view_func=lr_readmail ) @@ -122,7 +126,6 @@ def route(app): app.add_url_rule("/raw/<folder>/<msgid>", endpoint="raw", view_func=lr_rawmail) lr_writemail = login_required(writemail) - app.add_url_rule("/write", endpoint="write", view_func=lr_writemail) app.add_url_rule("/<lang_code>/write", endpoint="write", view_func=lr_writemail) app.add_url_rule( "/write", endpoint="send", view_func=login_required(sendmail), methods=["POST"] |