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 \
&& apk del --no-cache build-dep
COPY --from=assets static ./mailu/static_files/static
COPY --from=assets static ./mailu/static
COPY mailu ./mailu
COPY migrations ./migrations
COPY start.py /start.py

@ -11,7 +11,7 @@ import hmac
def create_app_from_config(config):
""" 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)
# 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.login.init_app(app)
utils.login.user_loader(models.User.get)
utils.proxy.init_app(app)
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()
@ -58,8 +57,8 @@ def create_app_from_config(config):
)
# Import views
from mailu import ui, internal, sso, static_files
app.register_blueprint(ui.ui, url_prefix='/ui')
from mailu import ui, internal, sso
app.register_blueprint(ui.ui, url_prefix=app.config['WEB_ADMIN'])
app.register_blueprint(internal.internal, url_prefix='/internal')
app.register_blueprint(sso.sso, url_prefix='/sso')
return app

@ -1,5 +1,5 @@
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 *

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

@ -1,6 +1,6 @@
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 *

@ -75,7 +75,7 @@
</a>
</li>
<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>
<p>{% trans %}Antispam{% endtrans %}</p>
</a>

@ -95,26 +95,6 @@ def get_locale():
flask.session['language'] = 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
migrate = flask_migrate.Migrate()

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

Loading…
Cancel
Save