Skip to content

Commit bd60e6e

Browse files
authored
Warn and fix missing mime types (#1050)
1 parent a3d79aa commit bd60e6e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: docs/source/about/changelog.rst

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
2323
Unreleased
2424
----------
2525

26+
**Changed**
27+
28+
- :pull:`1050` - Warn and attempt to fix missing mime types, which can result in ``reactpy.run`` not working as expected.
29+
2630
**Fixed**
2731

2832
- :issue:`930` - better traceback for JSON serialization errors (via :pull:`1008`)

Diff for: src/py/reactpy/reactpy/backend/__init__.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import mimetypes
2+
from logging import getLogger
3+
4+
_logger = getLogger(__name__)
5+
6+
# Fix for missing mime types due to OS corruption/misconfiguration
7+
# Example: https://github.com/encode/starlette/issues/829
8+
if not mimetypes.inited:
9+
mimetypes.init()
10+
for extension, mime_type in {
11+
".js": "application/javascript",
12+
".css": "text/css",
13+
".json": "application/json",
14+
}.items():
15+
if not mimetypes.types_map.get(extension): # pragma: no cover
16+
_logger.warning(
17+
"Mime type '%s = %s' is missing. Please research how to "
18+
"fix missing mime types on your operating system.",
19+
extension,
20+
mime_type,
21+
)
22+
mimetypes.add_type(mime_type, extension)

0 commit comments

Comments
 (0)