☔ Make sure js/css mime types are always correct

Even if we are running on windows and something is borked in the
registry...

Closes #3367
This commit is contained in:
Gina Häußge committed 2019-12-03 18:03:11 +01:00
1 parent 231a796200
commit 0c77014903
1 file changed
+15 -1
+15 -1
View File
@@ -31,6 +31,7 @@ import os
import sys
import logging
import logging.config
import mimetypes
import atexit
import signal
import base64
@@ -279,10 +280,12 @@ class Server(object):
self._setup_heartbeat_logging()
pluginManager = self._plugin_manager
# monkey patch some stuff
# monkey patch/fix some stuff
util.tornado.fix_json_encode()
util.flask.fix_flask_jsonify()
self._setup_mimetypes()
additional_translation_folders = []
if not safe_mode:
additional_translation_folders += [self._settings.getBaseFolder("translations")]
@@ -1369,6 +1372,17 @@ class Server(object):
self._logger.exception("Error processing after_request hooks from plugin {}".format(plugin),
extra=dict(plugin=plugin))
def _setup_mimetypes(self):
# Safety measures for Windows... apparently the mimetypes module takes its translation from the windows
# registry, and if for some weird reason that gets borked the reported MIME types can be all over the place.
# Since at least in Chrome that can cause hilarious issues with JS files (refusal to run them and thus a
# borked UI) we make sure that .js always maps to the correct application/javascript, and also throw in a
# .css -> text/css for good measure.
#
# See #3367
mimetypes.add_type("application/javascript", ".js")
mimetypes.add_type("text/css", ".css")
def _setup_assets(self):
global app
global assets