Get rid of complicated prefix logic. Further simplify /static handling and nginx config.

master
Dimitri Huisman 3 years ago
parent da788ddee3
commit fb0f005343

@ -38,7 +38,7 @@ RUN set -eu \
&& pip3 install -r requirements.txt \ && pip3 install -r requirements.txt \
&& apk del --no-cache build-dep && apk del --no-cache build-dep
COPY --from=assets static ./mailu/static_files/static COPY --from=assets static ./mailu/static
COPY mailu ./mailu COPY mailu ./mailu
COPY migrations ./migrations COPY migrations ./migrations
COPY start.py /start.py COPY start.py /start.py

@ -11,7 +11,7 @@ import hmac
def create_app_from_config(config): def create_app_from_config(config):
""" Create a new application based on the given configuration """ Create a new application based on the given configuration
""" """
app = flask.Flask(__name__, static_folder='static_files', static_url_path='') app = flask.Flask(__name__, static_folder='static', static_url_path='/static')
app.cli.add_command(manage.mailu) app.cli.add_command(manage.mailu)
# Bootstrap is used for error display and flash messages # Bootstrap is used for error display and flash messages
@ -25,7 +25,6 @@ def create_app_from_config(config):
utils.babel.init_app(app) utils.babel.init_app(app)
utils.login.init_app(app) utils.login.init_app(app)
utils.login.user_loader(models.User.get) utils.login.user_loader(models.User.get)
utils.proxy.init_app(app)
utils.migrate.init_app(app, models.db) utils.migrate.init_app(app, models.db)
app.device_cookie_key = hmac.new(bytearray(app.secret_key, 'utf-8'), bytearray('DEVICE_COOKIE_KEY', 'utf-8'), 'sha256').digest() app.device_cookie_key = hmac.new(bytearray(app.secret_key, 'utf-8'), bytearray('DEVICE_COOKIE_KEY', 'utf-8'), 'sha256').digest()
@ -58,8 +57,8 @@ def create_app_from_config(config):
) )
# Import views # Import views
from mailu import ui, internal, sso, static_files from mailu import ui, internal, sso
app.register_blueprint(ui.ui, url_prefix='/ui') app.register_blueprint(ui.ui, url_prefix=app.config['WEB_ADMIN'])
app.register_blueprint(internal.internal, url_prefix='/internal') app.register_blueprint(internal.internal, url_prefix='/internal')
app.register_blueprint(sso.sso, url_prefix='/sso') app.register_blueprint(sso.sso, url_prefix='/sso')
return app return app

@ -1,5 +1,5 @@
from flask import Blueprint from flask import Blueprint
sso = Blueprint('sso', __name__, template_folder='templates') sso = Blueprint('sso', __name__, static_folder='None' ,template_folder='templates')
from mailu.sso.views import * from mailu.sso.views import *

@ -8,8 +8,8 @@
<meta name="description" content="{% trans %}Admin page for{% endtrans %} {{ config["SITENAME"] }}"> <meta name="description" content="{% trans %}Admin page for{% endtrans %} {{ config["SITENAME"] }}">
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Mailu-Admin | {{ config["SITENAME"] }}</title> <title>Mailu-Admin | {{ config["SITENAME"] }}</title>
<link rel="stylesheet" href="/static/vendor.css"> <link rel="stylesheet" href="{{ url_for('static', filename='vendor.css') }}">
<link rel="stylesheet" href="/static/app.css"> <link rel="stylesheet" href="{{ url_for('static', filename='app.css') }}">
</head> </head>
<body class="hold-transition sidebar-mini layout-fixed"> <body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper"> <div class="wrapper">
@ -80,7 +80,7 @@
</span> </span>
</footer> </footer>
</div> </div>
<script src="/static/vendor.js"></script> <script src="{{ url_for('static', filename='vendor.js') }}"></script>
<script src="/static/app.js"></script> <script src="{{ url_for('static', filename='app.js') }}"></script>
</body> </body>
</html> </html>

@ -1,6 +1,6 @@
from flask import Blueprint from flask import Blueprint
ui = Blueprint('ui', __name__, static_folder='static', template_folder='templates') ui = Blueprint('ui', __name__, static_folder='None', template_folder='templates')
from mailu.ui.views import * from mailu.ui.views import *

@ -75,7 +75,7 @@
</a> </a>
</li> </li>
<li class="nav-item" role="none"> <li class="nav-item" role="none">
<a href="{{ config["WEB_ADMIN"] }}/antispam/" data-clicked="{{ url_for('.antispam') }}" target="_blank" class="nav-link" role="menuitem"> <a href="{{ config["WEB_ADMIN"] }}/antispam" data-clicked="{{ url_for('.antispam') }}" target="_blank" class="nav-link" role="menuitem">
<i class="nav-icon fas fa-trash-alt"></i> <i class="nav-icon fas fa-trash-alt"></i>
<p>{% trans %}Antispam{% endtrans %}</p> <p>{% trans %}Antispam{% endtrans %}</p>
</a> </a>

@ -95,26 +95,6 @@ def get_locale():
flask.session['language'] = language flask.session['language'] = language
return language return language
# Proxy fixer
class PrefixMiddleware(object):
""" fix proxy headers """
def __init__(self):
self.app = None
def __call__(self, environ, start_response):
prefix = environ.get('HTTP_X_FORWARDED_PREFIX', '')
if prefix:
environ['SCRIPT_NAME'] = prefix
return self.app(environ, start_response)
def init_app(self, app):
self.app = fixers.ProxyFix(app.wsgi_app, x_for=1, x_proto=1)
app.wsgi_app = self
proxy = PrefixMiddleware()
# Data migrate # Data migrate
migrate = flask_migrate.Migrate() migrate = flask_migrate.Migrate()

@ -183,29 +183,18 @@ http {
{% endif %} {% endif %}
{% if ADMIN == 'true' %} {% if ADMIN == 'true' %}
location {{ WEB_ADMIN }} { location {{ WEB_ADMIN }} {
return 301 {{ WEB_ADMIN }}/ui;
}
location ~ {{ WEB_ADMIN }}/ui {
rewrite ^{{ WEB_ADMIN }}/(.*) /$1 break;
include /etc/nginx/proxy.conf; include /etc/nginx/proxy.conf;
proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }};
proxy_pass http://$admin; proxy_pass http://$admin;
expires $expires; expires $expires;
} }
location {{ WEB_ADMIN }}/antispam { location ~ {{ WEB_ADMIN }}/antispam/ {
rewrite ^{{ WEB_ADMIN }}/antispam/(.*) /$1 break; rewrite ^{{ WEB_ADMIN }}/antispam/(.*) /$1 break;
auth_request /internal/auth/admin; auth_request /internal/auth/admin;
proxy_set_header X-Real-IP ""; proxy_set_header X-Real-IP "";
proxy_set_header X-Forwarded-For ""; proxy_set_header X-Forwarded-For "";
proxy_pass http://$antispam; proxy_pass http://$antispam;
} }
location ^~ {{ WEB_ADMIN }}/sso {
include /etc/nginx/proxy.conf;
rewrite ^{{ WEB_ADMIN }}/(.*) /$1 redirect;
}
{% endif %} {% endif %}
{% if WEBDAV != 'none' %} {% if WEBDAV != 'none' %}

Loading…
Cancel
Save