diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 56cd681f6..623be642a 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -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