Skip to content

Commit

Permalink
Add mount_path for mounting app at sub-path
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jul 27, 2023
1 parent e42e03c commit 93f69ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions jupyverse_api/jupyverse_api/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging
from collections import defaultdict
from typing import Dict, List
Expand All @@ -16,8 +18,13 @@ class App:
_app: FastAPI
_router_paths: Dict[str, List[str]]

def __init__(self, app: FastAPI):
self._app = app
def __init__(self, app: FastAPI, mount_path: str | None = None):
if mount_path is None:
self._app = app
else:
subapi = FastAPI()
app.mount(mount_path, subapi)
self._app = subapi
app.add_exception_handler(RedirectException, _redirect_exception_handler)
self._router_paths = defaultdict(list)

Expand Down
10 changes: 9 additions & 1 deletion jupyverse_api/jupyverse_api/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@


class AppComponent(Component):
def __init__(
self,
*,
mount_path: str | None = None,
) -> None:
super().__init__()
self.mount_path = mount_path

async def start(
self,
ctx: Context,
) -> None:
app = await ctx.request_resource(FastAPI)

_app = App(app)
_app = App(app, mount_path=self.mount_path)
ctx.add_resource(_app)


Expand Down

0 comments on commit 93f69ef

Please sign in to comment.