Skip to content

Commit

Permalink
☔ Make sure js/css mime types are always correct
Browse files Browse the repository at this point in the history
Even if we are running on windows and something is borked in the
registry...

Closes #3367
  • Loading branch information
foosel committed Dec 3, 2019
1 parent 231a796 commit 0c77014
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/octoprint/server/__init__.py
Expand Up @@ -31,6 +31,7 @@
import sys
import logging
import logging.config
import mimetypes
import atexit
import signal
import base64
Expand Down Expand Up @@ -279,10 +280,12 @@ def run(self):
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")]
Expand Down Expand Up @@ -1369,6 +1372,17 @@ def _add_plugin_request_handlers_to_blueprints(self, *blueprints):
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
Expand Down

0 comments on commit 0c77014

Please sign in to comment.