Skip to content

Commit e652eb8

Browse files
authored
Revert "Use StaticFiles for directories in static routes (#29026)" (#29131)
1 parent 5149910 commit e652eb8

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

python_modules/dagster-webserver/dagster_webserver/webserver.py

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import gzip
22
import io
33
import mimetypes
4-
import os
54
import uuid
6-
from os import path
5+
from os import path, walk
76
from typing import Generic, Optional, TypeVar
87

98
import dagster._check as check
@@ -33,7 +32,6 @@
3332
StreamingResponse,
3433
)
3534
from starlette.routing import Mount, Route, WebSocketRoute
36-
from starlette.staticfiles import StaticFiles
3735
from starlette.types import Message
3836

3937
from dagster_webserver.external_assets import (
@@ -260,24 +258,12 @@ def _static_file(path, file_path):
260258

261259
routes = []
262260
base_dir = self.relative_path("webapp/build/")
263-
with os.scandir(base_dir) as entries:
264-
for entry in entries:
265-
if entry.is_symlink():
266-
continue
267-
relative_path = "/" + path.relpath(entry.path, base_dir).replace(path.sep, "/")
268-
if entry.is_file():
269-
routes.append(_static_file(relative_path, entry.path))
270-
elif entry.is_dir():
271-
routes.append(
272-
Mount(
273-
relative_path,
274-
StaticFiles(
275-
directory=entry.path,
276-
check_dir=False,
277-
),
278-
name="root_static",
279-
)
280-
)
261+
for subdir, _, files in walk(base_dir):
262+
for file in files:
263+
full_path = path.join(subdir, file)
264+
# Replace path.sep to make sure our routes use forward slashes on windows
265+
mount_path = "/" + full_path[len(base_dir) :].replace(path.sep, "/")
266+
routes.append(_static_file(mount_path, full_path))
281267

282268
# No build directory, this happens in a test environment. Don't fail loudly since we already have other tests that will fail loudly if
283269
# there is in fact no build

python_modules/dagster-webserver/dagster_webserver_tests/webserver/test_app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_static_resources(test_client: TestClient):
8181
assert response.status_code == 200, response.text
8282
assert response.headers["content-type"] != "text/html"
8383

84-
response = test_client.get("vendor/graphiql/graphiql.min.js")
84+
response = test_client.get("/vendor/graphql-playground/middleware.js")
8585
assert response.status_code == 200, response.text
8686
assert response.headers["content-type"] != "application/js"
8787

0 commit comments

Comments
 (0)