Warn and fix missing mime types (#1050)
This commit is contained in:
parent
a3d79aa8f5
commit
bd60e6e7e1
2 changed files with 26 additions and 0 deletions
|
@ -23,6 +23,10 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
|
|||
Unreleased
|
||||
----------
|
||||
|
||||
**Changed**
|
||||
|
||||
- :pull:`1050` - Warn and attempt to fix missing mime types, which can result in ``reactpy.run`` not working as expected.
|
||||
|
||||
**Fixed**
|
||||
|
||||
- :issue:`930` - better traceback for JSON serialization errors (via :pull:`1008`)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import mimetypes
|
||||
from logging import getLogger
|
||||
|
||||
_logger = getLogger(__name__)
|
||||
|
||||
# Fix for missing mime types due to OS corruption/misconfiguration
|
||||
# Example: https://github.com/encode/starlette/issues/829
|
||||
if not mimetypes.inited:
|
||||
mimetypes.init()
|
||||
for extension, mime_type in {
|
||||
".js": "application/javascript",
|
||||
".css": "text/css",
|
||||
".json": "application/json",
|
||||
}.items():
|
||||
if not mimetypes.types_map.get(extension): # pragma: no cover
|
||||
_logger.warning(
|
||||
"Mime type '%s = %s' is missing. Please research how to "
|
||||
"fix missing mime types on your operating system.",
|
||||
extension,
|
||||
mime_type,
|
||||
)
|
||||
mimetypes.add_type(mime_type, extension)
|
Loading…
Reference in a new issue