Skip to content
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

Create catch-all/fallback route for UI app #932

Merged
merged 16 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions conda-store-server/conda_store_server/_internal/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,32 @@ async def exception_handler(request, exc):
# docker registry api specification does not support a url_prefix
app.include_router(views.router_registry)

if self.enable_ui:
if self.enable_metrics:
app.include_router(
views.router_ui,
prefix=trim_slash(self.url_prefix) + "/admin",
views.router_metrics,
prefix=trim_slash(self.url_prefix),
)

if self.additional_routes:
for path, method, func in self.additional_routes:
getattr(app, method)(path, name=func.__name__)(func)

if isinstance(self.conda_store.storage, storage.LocalStorage):
self.conda_store.storage.storage_url = (
f"{trim_slash(self.url_prefix)}/storage"
)
app.mount(
self.conda_store.storage.storage_url,
StaticFiles(directory=self.conda_store.storage.storage_path),
name="static-storage",
)

# This needs to come at the end because if the UI is enabled,
# it becomes the catch all route
if self.enable_ui:
peytondmurray marked this conversation as resolved.
Show resolved Hide resolved
app.include_router(
views.router_conda_store_ui,
prefix=trim_slash(self.url_prefix),
views.router_ui,
prefix=trim_slash(self.url_prefix) + "/admin",
)

# serving static files
Expand Down Expand Up @@ -336,26 +353,12 @@ async def favicon():
)
)

if self.enable_metrics:
# Put this at the very end
app.include_router(
views.router_metrics,
views.router_conda_store_ui,
prefix=trim_slash(self.url_prefix),
)

if self.additional_routes:
for path, method, func in self.additional_routes:
getattr(app, method)(path, name=func.__name__)(func)

if isinstance(self.conda_store.storage, storage.LocalStorage):
self.conda_store.storage.storage_url = (
f"{trim_slash(self.url_prefix)}/storage"
)
app.mount(
self.conda_store.storage.storage_url,
StaticFiles(directory=self.conda_store.storage.storage_path),
name="static-storage",
)

return app

def _check_worker(self, delay=5):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
REACT_APP_URL_BASENAME: new URL("{{ url_for('get_conda_store_ui') }}").pathname
};
</script>
<script defer src="static/conda-store-ui/main.js"></script>
<link href="static/conda-store-ui/main.css" rel="stylesheet">
<script defer src="{{ url_for('get_conda_store_ui') }}static/conda-store-ui/main.js"></script>
<link href="{{ url_for('get_conda_store_ui') }}static/conda-store-ui/main.css" rel="stylesheet">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding url_for('get_conda_store_ui') was the only way I could figure out how to put the url_prefix here.

Why is this change needed? Previously, the server would only serve the UI app at url_prefix (e.g., either at "/" or "/conda-store", depending on configuration).

However, this PR allows the UI app to be loaded at /conda-store/default/test, for example. At that URL, this page would try to fetch the JavaScript and CSS at:

  • /conda-store/default/static/conda-store-ui/main.js
  • /conda-store/default/static/main.css

These routes end up matching the catch-all, which means the server serves this template page for those requests instead of the desired JavaScript and CSS.

</head>
<body>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@


@router_conda_store_ui.get("/")
@router_conda_store_ui.get("/{full_path:path}")
peytondmurray marked this conversation as resolved.
Show resolved Hide resolved
async def get_conda_store_ui(
request: Request,
full_path: str,
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
templates=Depends(dependencies.get_templates),
):
context = {
Expand Down
Loading