ben-pr-p
ben-pr-p•9mo ago

Asgi server

When using the asgi app functionality, I'm getting a 404 for everything except the root. Any ideas?
server = (
marimo.create_asgi_app()
.with_app(path="", root="./index.py")
.with_app(path="/easy-entry", root="./production/easy-entry.py")
.with_app(
path="/print-leader-coverage",
root="./production/print-leader-coverage.py",
)
.with_app(
path="/print-section",
root="./production/print-section.py",
)
)

# Create a FastAPI app
app = FastAPI()

app.mount("/", server.build())
server = (
marimo.create_asgi_app()
.with_app(path="", root="./index.py")
.with_app(path="/easy-entry", root="./production/easy-entry.py")
.with_app(
path="/print-leader-coverage",
root="./production/print-leader-coverage.py",
)
.with_app(
path="/print-section",
root="./production/print-section.py",
)
)

# Create a FastAPI app
app = FastAPI()

app.mount("/", server.build())
/ works and is a full notebook, /print-section gives me a marimo 404
5 Replies
Myles Scolnick
Myles Scolnick•9mo ago
What happens when you visit /easy-entry/ (with a slash at the end)
ben-pr-p
ben-pr-pOP•9mo ago
Same thing If I mount it here:
app.mount("/marimo", server.build())
app.mount("/marimo", server.build())
I also can't visit /marimo (404)
ben-pr-p
ben-pr-pOP•9mo ago
Ok I figured it out. This fixed it (I figured it out from looking at the smoke test file: https://github.com/marimo-team/marimo/blob/7a1459dfa5088656b76feeea40fb7109e3f3b221/marimo/_smoke_tests/custom_server/my_server.py
GitHub
marimo/marimo/_smoke_tests/custom_server/my_server.py at 7a1459dfa5...
A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git. - marimo-team/marimo
ben-pr-p
ben-pr-pOP•9mo ago
The fix is to put the index notebook last: marimo.create_asgi_app() .with_app(path="/easy-entry", root="./production/easy-entry.py") .with_app( path="/print-leader-coverage", root="./production/print-leader-coverage.py", ) .with_app( path="/print-section", root="./production/print-section.py", ) .with_app(path="", root="./index.py") It was matching everything, and so it was index.py's notebook serving that 404 I'm not 100% sure I'd call that a bug, but it'd be worth documenting it here since this example doesn't work: https://docs.marimo.io/guides/deploying/programmatically.html Thanks again for shipping this though! My users are gonna love it 🙂
Myles Scolnick
Myles Scolnick•9mo ago
oh nice! now that you say that, it makes a lot of sense. i think we should handle this and document it for sure, thanks for debugging this