-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create_asgi_app to programatically run marimo apps #1002
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! I can definitely see this unlocking more use cases. Two small comments, o.w. looks good.
marimo/_server/api/middleware.py
Outdated
# class StripBaseURLMiddleware: | ||
# def __init__(self, app: ASGIApp, base_url: str) -> None: | ||
# self.app = app | ||
# self.base_url = base_url | ||
|
||
async def __call__( | ||
self, scope: Scope, receive: Receive, send: Send | ||
) -> None: | ||
# If not HTTP, skip | ||
if scope["type"] != "http": | ||
return await self.app(scope, receive, send) | ||
# async def __call__( | ||
# self, scope: Scope, receive: Receive, send: Send | ||
# ) -> None: | ||
# # If not HTTP, skip | ||
# if scope["type"] != "http": | ||
# return await self.app(scope, receive, send) | ||
|
||
# If base URL is empty, skip | ||
if self.base_url == "" or self.base_url == "/": | ||
return await self.app(scope, receive, send) | ||
# # If base URL is empty, skip | ||
# if self.base_url == "" or self.base_url == "/": | ||
# return await self.app(scope, receive, send) | ||
|
||
request = Request(scope) | ||
# request = Request(scope) | ||
|
||
# If under common infra routes, allow | ||
if request.url.path in ALLOWED_BASE_URLS: | ||
return await self.app(scope, receive, send) | ||
# # If under common infra routes, allow | ||
# if request.url.path in ALLOWED_BASE_URLS: | ||
# return await self.app(scope, receive, send) | ||
|
||
# If not under base URL or under infra routes, return 404 | ||
# Otherwise, this may hide real issues | ||
if not request.url.path.startswith(self.base_url): | ||
response = JSONResponse({"error": "Not found"}, status_code=404) | ||
return await response(scope, receive, send) | ||
# # If not under base URL or under infra routes, return 404 | ||
# # Otherwise, this may hide real issues | ||
# if not request.url.path.startswith(self.base_url): | ||
# response = JSONResponse({"error": "Not found"}, status_code=404) | ||
# return await response(scope, receive, send) | ||
|
||
# Strip base URL | ||
scope["path"] = scope["path"][len(self.base_url) :] | ||
if not scope["path"].startswith("/"): | ||
scope["path"] = "/" + scope["path"] | ||
return await self.app(scope, receive, send) | ||
# # Strip base URL | ||
# scope["path"] = scope["path"][len(self.base_url) :] | ||
# if not scope["path"].startswith("/"): | ||
# scope["path"] = "/" + scope["path"] | ||
# return await self.app(scope, receive, send) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can all this dead code be deleted?
tests/_server/asgi.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asgi.py
-> test_asgi.py
, to make sure pytest runs it.
This exposes a new function from the
marimo
module:create_asgi_app
. Which is a builder to add many marimo apps:Closes #904 #395
Regarding the API:
create_asgi_app
so 1) we can share configs, 2) we can initialize shared singletons between the appsroot
instead offilename
so we can latter supportdirs
orcode
It would look something like: