Skip to content

Commit

Permalink
Create catch all/fallback route for UI app
Browse files Browse the repository at this point in the history
  • Loading branch information
gabalafou committed Oct 29, 2024
1 parent 24ed0a4 commit 61590a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
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:
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">
</head>
<body>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

router_conda_store_ui = APIRouter(tags=["conda-store-ui"])


@router_conda_store_ui.get("/")
@router_conda_store_ui.get("/{full_path:path}")
async def get_conda_store_ui(
request: Request,
full_path: str,
templates=Depends(dependencies.get_templates),
):
context = {
Expand Down

0 comments on commit 61590a0

Please sign in to comment.