diff --git a/README.md b/README.md index 8c0e87e..3030033 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ The gallery application backend can be run as a standalone server app by executi jupyterlab-gallery ``` +When run in JupyterHub context (with `jupyterhub` package installed), the standalone app will adopt the JupyterHub modifications to the single-user server. + ## Requirements - JupyterLab >= 4.0.0 diff --git a/jupyterlab_gallery/app.py b/jupyterlab_gallery/app.py index 7833bcd..c1a0387 100644 --- a/jupyterlab_gallery/app.py +++ b/jupyterlab_gallery/app.py @@ -4,6 +4,18 @@ from .manager import GalleryManager +try: + from jupyterhub.singleuser.mixins import make_singleuser_app +except ImportError: + + def make_singleuser_app(cls): + return cls + + +# if jupyterhub is installed, apply jupyterhub patches +ServerAppClass = make_singleuser_app(ServerApp) + + class GalleryApp(ExtensionApp): name = "gallery" @@ -29,6 +41,8 @@ def initialize_handlers(self): self.log.info(f"Registered {self.name} server extension") + serverapp_class = ServerAppClass + @classmethod def make_serverapp(cls, **kwargs) -> ServerApp: """Instantiate the ServerApp @@ -38,6 +52,7 @@ def make_serverapp(cls, **kwargs) -> ServerApp: code (`kernels` service). """ server_app = super().make_serverapp(**kwargs) + assert isinstance(server_app, ServerAppClass) assert len(server_app.default_services) > 1 server_app.default_services = ("auth", "security") return server_app