Skip to content

Commit b08ff6e

Browse files
committed
Add indexpage option
1 parent e9a132d commit b08ff6e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

jupyter_server_proxy/config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from collections import namedtuple
1010
from .utils import call_with_asked_args
1111

12-
def _make_serverproxy_handler(name, command, environment, timeout, absolute_url, port):
12+
def _make_serverproxy_handler(name, command, environment, timeout, absolute_url, port, indexpage):
1313
"""
1414
Create a SuperviseAndProxyHandler subclass with given parameters
1515
"""
@@ -21,6 +21,7 @@ def __init__(self, *args, **kwargs):
2121
self.proxy_base = name
2222
self.absolute_url = absolute_url
2323
self.requested_port = port
24+
self.indexpage = indexpage
2425

2526
@property
2627
def process_args(self):
@@ -82,6 +83,7 @@ def make_handlers(base_url, server_processes):
8283
sp.timeout,
8384
sp.absolute_url,
8485
sp.port,
86+
sp.indexpage,
8587
)
8688
handlers.append((
8789
ujoin(base_url, sp.name, r'(.*)'), handler, dict(state={}),
@@ -93,7 +95,7 @@ def make_handlers(base_url, server_processes):
9395

9496
LauncherEntry = namedtuple('LauncherEntry', ['enabled', 'icon_path', 'title'])
9597
ServerProcess = namedtuple('ServerProcess', [
96-
'name', 'command', 'environment', 'timeout', 'absolute_url', 'port', 'launcher_entry'])
98+
'name', 'command', 'environment', 'timeout', 'absolute_url', 'port', 'indexpage', 'launcher_entry'])
9799

98100
def make_server_process(name, server_process_config):
99101
le = server_process_config.get('launcher_entry', {})
@@ -104,6 +106,7 @@ def make_server_process(name, server_process_config):
104106
timeout=server_process_config.get('timeout', 5),
105107
absolute_url=server_process_config.get('absolute_url', False),
106108
port=server_process_config.get('port', 0),
109+
indexpage=server_process_config.get('indexpage', ''),
107110
launcher_entry=LauncherEntry(
108111
enabled=le.get('enabled', True),
109112
icon_path=le.get('icon_path'),
@@ -144,6 +147,11 @@ class ServerProxy(Configurable):
144147
port
145148
Set the port that the service will listen on. The default is to automatically select an unused port.
146149
150+
indexpage
151+
If the root of the service is requested return this page instead.
152+
This is often referred to in web-server configurations as the index
153+
page.
154+
147155
launcher_entry
148156
A dictionary of various options for entries in classic notebook / jupyterlab launchers.
149157

jupyter_server_proxy/handlers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ class SuperviseAndProxyHandler(LocalProxyHandler):
340340

341341
def __init__(self, *args, **kwargs):
342342
self.requested_port = 0
343+
self.indexpage = ''
343344
super().__init__(*args, **kwargs)
344345

345346
def initialize(self, state):
@@ -435,6 +436,8 @@ async def ensure_process(self):
435436
async def proxy(self, port, path):
436437
if not path.startswith('/'):
437438
path = '/' + path
439+
if self.indexpage and (path == '/' or path.startswith == '/?'):
440+
path = '/' + self.indexpage + path[1:]
438441

439442
await self.ensure_process()
440443

0 commit comments

Comments
 (0)