Skip to content

fix: support starlette 0.33#413

Merged
maartenbreddels merged 1 commit intomasterfrom
12-05-fix_support_starlette_0.33
Dec 8, 2023
Merged

fix: support starlette 0.33#413
maartenbreddels merged 1 commit intomasterfrom
12-05-fix_support_starlette_0.33

Conversation

@maartenbreddels
Copy link
Contributor

@maartenbreddels maartenbreddels commented Dec 5, 2023

path now includes root_path so we need a different way to
remove it. It seems like route_root_path gives this information.

See Kludex/starlette#2361
Kludex/starlette#2352
Kludex/starlette#1336

Fixes #410

path now includes root_path so we need a different way to
remove it. It seems like route_root_path gives this information.

See Kludex/starlette#2361
Kludex/starlette#2352
Kludex/starlette#1336
Copy link
Contributor Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@maartenbreddels maartenbreddels merged commit a6b2a29 into master Dec 8, 2023
maartenbreddels added a commit to maartenbreddels/py-shiny that referenced this pull request Jun 28, 2024
When a shiny app is running under a prefix (root_path in ASGI terms),
the static files are not served correctly under pyodide.
This is because the ASGI path includes the prefix, and the root_path
should be removed.
Starlette 0.33 and 0.34 however, did not set root_path correctly,
and in those cases, we have to rely on route_path.

Related discussions:
 Kludex/starlette#2400
 Kludex/starlette#2361

A related fix we had in Solara:
 widgetti/solara#413

But this fix also did not seem to work for our situation at https://py.cafe

I logged the output of the relevant entries in the scope dict, together
with the starlette version:

```
scope 0.32.0 {'path': '/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
scope 0.33.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '', 'route_root_path': '/lib/strftime-0.9.2', 'route_path': '/strftime-min.js'}
scope 0.34.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '', 'route_root_path': '/lib/strftime-0.9.2', 'route_path': '/strftime-min.js'}
scope 0.35.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
scope 0.36.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
scope 0.37.2 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
```

This was using a similar situation as on py.cafe:
```python
....
routes = [
    Mount('/static', app=app_static),
    Mount('/_app', app=app_shiny)
]

app = Starlette(routes=routes)
```

Which led me to the following fix, making shiny work under pyodide
in combination with a prefix with the above mentioned versions of starlette.
maartenbreddels added a commit to maartenbreddels/py-shiny that referenced this pull request Jun 28, 2024
When a shiny app is running under a prefix (root_path in ASGI terms),
the static files are not served correctly under pyodide.
This is because the ASGI path includes the root_path, and the root_path
should be removed.
Starlette 0.33 and 0.34 however, did not set root_path correctly,
and in those cases, we have to rely on route_path.

Related discussions:
 Kludex/starlette#2400
 Kludex/starlette#2361

A related fix we had in Solara:
 widgetti/solara#413

But this fix also did not seem to work for our situation at https://py.cafe

I logged the output of the relevant entries in the scope dict, together
with the starlette version:

```
starlette 0.32.0 {'path': '/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
starlette 0.33.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '', 'route_root_path': '/lib/strftime-0.9.2', 'route_path': '/strftime-min.js'}
starlette 0.34.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '', 'route_root_path': '/lib/strftime-0.9.2', 'route_path': '/strftime-min.js'}
starlette 0.35.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
starlette 0.36.0 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
starlette 0.37.2 {'path': '/_app/lib/strftime-0.9.2/strftime-min.js', 'root_path': '/_app/lib/strftime-0.9.2'}
```

This was using a similar situation as on py.cafe:
```python
....
routes = [
    Mount('/static', app=app_static),
    Mount('/_app', app=app_shiny)
]

app = Starlette(routes=routes)
```

Which led me to the following fix, making shiny work under pyodide
in combination with a prefix with the above mentioned versions of starlette.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: mounting under starlette 0.33 is broken

1 participant