mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 22:43:00 +00:00
add default hub route via Proxy.add_route
instead of relying on default target
This commit is contained in:
@@ -1433,6 +1433,7 @@ class JupyterHub(Application):
|
|||||||
self.exit(1)
|
self.exit(1)
|
||||||
else:
|
else:
|
||||||
self.log.info("Not starting proxy")
|
self.log.info("Not starting proxy")
|
||||||
|
yield self.proxy.add_hub_route(self.hub)
|
||||||
|
|
||||||
# start the service(s)
|
# start the service(s)
|
||||||
for service_name, service in self._service_map.items():
|
for service_name, service in self._service_map.items():
|
||||||
|
@@ -107,6 +107,10 @@ class Proxy(LoggingConfigurable):
|
|||||||
- Checks host value vs host-based routing.
|
- Checks host value vs host-based routing.
|
||||||
- Ensures trailing slash on path.
|
- Ensures trailing slash on path.
|
||||||
"""
|
"""
|
||||||
|
if routespec == '/':
|
||||||
|
# / is the default route.
|
||||||
|
# don't check host-based routing
|
||||||
|
return routespec
|
||||||
# check host routing
|
# check host routing
|
||||||
host_route = not routespec.startswith('/')
|
host_route = not routespec.startswith('/')
|
||||||
if host_route and not self.host_routing:
|
if host_route and not self.host_routing:
|
||||||
@@ -281,6 +285,11 @@ class Proxy(LoggingConfigurable):
|
|||||||
user_routes = {r['data']['user'] for r in routes.values() if 'user' in r['data']}
|
user_routes = {r['data']['user'] for r in routes.values() if 'user' in r['data']}
|
||||||
futures = []
|
futures = []
|
||||||
db = self.db
|
db = self.db
|
||||||
|
|
||||||
|
if '/' not in routes:
|
||||||
|
self.log.warning("Adding missing default route")
|
||||||
|
self.add_hub_route(self.app.hub)
|
||||||
|
|
||||||
for orm_user in db.query(User):
|
for orm_user in db.query(User):
|
||||||
user = user_dict[orm_user]
|
user = user_dict[orm_user]
|
||||||
if user.running:
|
if user.running:
|
||||||
@@ -315,9 +324,15 @@ class Proxy(LoggingConfigurable):
|
|||||||
for f in futures:
|
for f in futures:
|
||||||
yield f
|
yield f
|
||||||
|
|
||||||
|
def add_hub_route(self, hub):
|
||||||
|
"""Add the default route for the Hub"""
|
||||||
|
self.log.info("Adding default route for Hub: / => %s", hub.host)
|
||||||
|
return self.add_route('/', self.hub.host)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def restore_routes(self):
|
def restore_routes(self):
|
||||||
self.log.info("Setting up routes on new proxy")
|
self.log.info("Setting up routes on new proxy")
|
||||||
|
yield self.add_hub_route(self.app.hub)
|
||||||
yield self.add_all_users(self.app.users)
|
yield self.add_all_users(self.app.users)
|
||||||
yield self.add_all_services(self.app.services)
|
yield self.add_all_services(self.app.services)
|
||||||
self.log.info("New proxy back up and good to go")
|
self.log.info("New proxy back up and good to go")
|
||||||
@@ -379,7 +394,6 @@ class ConfigurableHTTPProxy(Proxy):
|
|||||||
'--port', str(public_server.port),
|
'--port', str(public_server.port),
|
||||||
'--api-ip', api_server.ip,
|
'--api-ip', api_server.ip,
|
||||||
'--api-port', str(api_server.port),
|
'--api-port', str(api_server.port),
|
||||||
'--default-target', self.hub.host,
|
|
||||||
'--error-target', url_path_join(self.hub.url, 'error'),
|
'--error-target', url_path_join(self.hub.url, 'error'),
|
||||||
]
|
]
|
||||||
if self.app.subdomain_host:
|
if self.app.subdomain_host:
|
||||||
@@ -464,7 +478,7 @@ class ConfigurableHTTPProxy(Proxy):
|
|||||||
path = self.validate_routespec(routespec)
|
path = self.validate_routespec(routespec)
|
||||||
# CHP always wants to start with /
|
# CHP always wants to start with /
|
||||||
if not path.startswith('/'):
|
if not path.startswith('/'):
|
||||||
path = path + '/'
|
path = '/' + path
|
||||||
# BUG: CHP doesn't seem to like trailing slashes on some endpoints (DELETE)
|
# BUG: CHP doesn't seem to like trailing slashes on some endpoints (DELETE)
|
||||||
if path != '/' and path.endswith('/'):
|
if path != '/' and path.endswith('/'):
|
||||||
path = path.rstrip('/')
|
path = path.rstrip('/')
|
||||||
|
@@ -43,7 +43,7 @@ def test_external_proxy(request, io_loop):
|
|||||||
'--port', str(app.port),
|
'--port', str(app.port),
|
||||||
'--api-ip', proxy_ip,
|
'--api-ip', proxy_ip,
|
||||||
'--api-port', str(proxy_port),
|
'--api-port', str(proxy_port),
|
||||||
'--default-target', 'http://%s:%i' % (app.hub_ip, app.hub_port),
|
'--log-level=debug',
|
||||||
]
|
]
|
||||||
if app.subdomain_host:
|
if app.subdomain_host:
|
||||||
cmd.append('--host-routing')
|
cmd.append('--host-routing')
|
||||||
@@ -90,7 +90,7 @@ def test_external_proxy(request, io_loop):
|
|||||||
|
|
||||||
routes = io_loop.run_sync(app.proxy.get_all_routes)
|
routes = io_loop.run_sync(app.proxy.get_all_routes)
|
||||||
|
|
||||||
assert list(routes.keys()) == ['/']
|
assert list(routes.keys()) == []
|
||||||
|
|
||||||
# poke the server to update the proxy
|
# poke the server to update the proxy
|
||||||
r = api_request(app, 'proxy', method='post')
|
r = api_request(app, 'proxy', method='post')
|
||||||
|
Reference in New Issue
Block a user