Skip to content

Commit 7124c89

Browse files
authored
Merge pull request #887 from krinsman/step7_7
Step7_7 (prepare base_url for traitlets by making it "private")
2 parents 18a5a9d + e83c73e commit 7124c89

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ $ docker run -p 8080:8080 -e 'GITHUB_OAUTH_KEY=YOURKEY' \
4343

4444
With this configured all GitHub API requests will go to your Enterprise instance so you can view all of your internal notebooks.
4545

46+
## Base URL
47+
48+
If the environment variable `JUPYTERHUB_SERVICE_PREFIX` is specified, then NBViewer _always_ uses the value of this environment variable as the base URL.
49+
50+
In the case that there is no value for `JUPYTERHUB_SERVICE_PREFIX`, then as a backup the value of the `--base-url` flag passed to the `python -m nbviewer` command on the command line will be used as the base URL.
51+
4652
## Local Development
4753

4854
### With Docker

nbviewer/app.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,13 @@ def _load_max_cache_uris(self):
132132
_static_url_prefix = Unicode()
133133
@default('_static_url_prefix')
134134
def _load_static_url_prefix(self):
135-
# Last '/' ensures that NBViewer still works regardless of whether user chooses e.g. '/static2/' pr '/static2' as their custom prefix
136-
return url_path_join(self.base_url, self.static_url_prefix, '/')
135+
# Last '/' ensures that NBViewer still works regardless of whether user chooses e.g. '/static2/' or '/static2' as their custom prefix
136+
return url_path_join(self._base_url, self.static_url_prefix, '/')
137137

138+
# prefer the JupyterHub defined service prefix over the CLI
138139
@cached_property
139-
def base_url(self):
140-
# prefer the JupyterHub defined service prefix over the CLI
141-
base_url = os.getenv("JUPYTERHUB_SERVICE_PREFIX", options.base_url)
142-
return base_url
140+
def _base_url(self):
141+
return os.getenv("JUPYTERHUB_SERVICE_PREFIX", options.base_url)
143142

144143
@cached_property
145144
def cache(self):
@@ -273,7 +272,7 @@ def init_tornado_application(self):
273272
user_gists_handler=self.user_gists_handler,
274273
)
275274
handler_kwargs = {'handler_names' : handler_names, 'handler_settings' : self.handler_settings}
276-
handlers = init_handlers(self.formats, options.providers, self.base_url, options.localfiles, **handler_kwargs)
275+
handlers = init_handlers(self.formats, options.providers, self._base_url, options.localfiles, **handler_kwargs)
277276

278277
# NBConvert config
279278
self.config.NbconvertApp.fileext = 'html'
@@ -288,7 +287,7 @@ def init_tornado_application(self):
288287
settings = dict(
289288
# Allow FileFindHandler to load static directories from e.g. a Docker container
290289
allow_remote_access=True,
291-
base_url=self.base_url,
290+
base_url=self._base_url,
292291
binder_base_url=options.binder_base_url,
293292
cache=self.cache,
294293
cache_expiry_max=options.cache_expiry_max,

0 commit comments

Comments
 (0)