NotThatGuy
NotThatGuy3w ago

Issues ASGI mount

Hi! I've been exploring integrations with the ASGI mount. I keep hitting issues when trying more complex scenarios than the intro docs / examples. It's hard to debug and introspect because a lot is bundled together, so I'm looking for some details: - what is bundled via create_asgi_app() and what is required for the app to run? (e.g., do I need user_config_manager?) - I found marimo._server.api.router.build_routes() but what is required / optional? - handling file paths when mounting is challenging (cwd for launching the server vs. main app dir vs. marimo ASGI subapp dir vs. marimo notebook path) - the redirect feature from create_redirect_to_slash() adds misdirection and should be opt-in - one potential source of challenge is the marimo app bundles HTTP, Websockets, and static files routes, but they might have different mount requirements for the main app (e.g., middlewares, conflicting paths) solution have a "core" ASGI app or set of routes with minimal features (no middleware, no LSP, no redirect) for developers. This would be in addition to the current "full ASGI app" that's more user-friendly I really tried fixing this myself, and I'm willing to contribute, but would require some guidance on how to approach it
5 Replies
Hall
Hall3w ago
Someone will reply to you shortly. In the meantime, this might help:
NotThatGuy
NotThatGuyOP3w ago
Issue with create_redirect_to_slash()
import fastapi
import marimo

marimo_server = (
marimo.create_asgi_app()
.with_app(path="/app1", root="marimo_nb.py")
.build()
)

app = fastapi.FastAPI()

# this works
# page found at `localhost:8001/app1`
app.mount("/", app=marimo_server, name="marimo") # this works
uvicorn.run(app, host="localhost", port=8001)

# this doesn't work
# url `localhost:8001/workspace/app1` gets redirected to `localhost:8001/app1` and fails
app.mount("/workspace", app=marimo_server, name="marimo")
uvicorn.run(app, host="localhost", port=8001)
import fastapi
import marimo

marimo_server = (
marimo.create_asgi_app()
.with_app(path="/app1", root="marimo_nb.py")
.build()
)

app = fastapi.FastAPI()

# this works
# page found at `localhost:8001/app1`
app.mount("/", app=marimo_server, name="marimo") # this works
uvicorn.run(app, host="localhost", port=8001)

# this doesn't work
# url `localhost:8001/workspace/app1` gets redirected to `localhost:8001/app1` and fails
app.mount("/workspace", app=marimo_server, name="marimo")
uvicorn.run(app, host="localhost", port=8001)
Maybe it has something to do with marimo._server.start.start(base_url=...)
Myles Scolnick
I think the redirect issue is related to https://github.com/marimo-team/marimo/issues/2938
GitHub
create_asgi_app: Marimo server mounted to non-root fails to fetch ...
The first GET request is successful but blank because it's looking for other resources in root path, not relative to where the app is mounted to. INFO: 10.91.2.13:5046 - "GET /marimo/motes...
Myles Scolnick
i dont think there is any LSP. (or rather it is a noop). as far as middleware, it is all the required middleware for the app to run. is there any that you'd like not included? we can make it configurable to remove them.
NotThatGuy
NotThatGuyOP2w ago
Thanks for the info! I agree with the linked issue that it relates to absolute / relative path and the mount point of the ASGI app. I'll continue hacking around to mount Marimo routes individually to my main app and report back if I find a solution.

Did you find this page helpful?