Fix blank page on Windows due to broken .js MIME type (#4674)
* Fix blank page on Windows due to broken .js MIME type in registry * Update studio/backend/main.py adding defensive suggestion by gemini where we make the mimetypes specific to windows platforms Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
parent
5d2dca801c
commit
a6c1f893fc
1 changed files with 13 additions and 0 deletions
|
|
@ -23,10 +23,23 @@ if _backend_dir not in sys.path:
|
|||
# See: https://github.com/python/cpython/issues/102396
|
||||
import _platform_compat # noqa: F401
|
||||
|
||||
import mimetypes
|
||||
import shutil
|
||||
import warnings
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
# Fix broken Windows registry MIME types. Some Windows installs map .js to
|
||||
# "text/plain" in the registry (HKCR\.js\Content Type). Python's mimetypes
|
||||
# module reads from the registry, and FastAPI/Starlette's StaticFiles uses
|
||||
# mimetypes.guess_type() to set Content-Type headers. Browsers enforce strict
|
||||
# MIME checking for ES module scripts (<script type="module">) and will refuse
|
||||
# to execute .js files served as text/plain — resulting in a blank page.
|
||||
# Calling add_type() *before* StaticFiles is instantiated ensures the correct
|
||||
# types are used regardless of the OS registry.
|
||||
if sys.platform == "win32":
|
||||
mimetypes.add_type("application/javascript", ".js")
|
||||
mimetypes.add_type("text/css", ".css")
|
||||
|
||||
# Suppress annoying dependency warnings in production
|
||||
if os.getenv("ENVIRONMENT_TYPE", "production") == "production":
|
||||
warnings.filterwarnings("ignore")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue