Skip to content

Commit ee39789

Browse files
authored
Merge pull request #36 from bollwyvl/fix/static-urls
Dynamically change static url, test with ssl and prefix
2 parents d211703 + 0087cb3 commit ee39789

File tree

6 files changed

+105
-16
lines changed

6 files changed

+105
-16
lines changed

jyve/exporter.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ class JyveExporter(HTMLExporter):
3737
"favicon.ico",
3838
"api/contents/",
3939
"lab/api/settings/@jupyterlab/apputils-extension:themes",
40+
"lab/api/settings/@jupyterlab/application-extension:sidebar",
4041
"lab/api/settings/@jupyterlab/codemirror-extension:commands",
4142
"lab/api/settings/@jupyterlab/docmanager-extension:plugin",
4243
"lab/api/settings/@jupyterlab/fileeditor-extension:plugin",
4344
"lab/api/settings/@jupyterlab/notebook-extension:tracker",
4445
"lab/api/settings/@jupyterlab/shortcuts-extension:plugin",
46+
"lab/api/settings/@jupyterlab/extensionmanager-extension:plugin",
4547
],
4648
help="additional notebook urls to cache",
4749
config=True,
@@ -55,6 +57,8 @@ class JyveExporter(HTMLExporter):
5557
{
5658
"api/sessions": [],
5759
"api/terminals": [],
60+
"api/nbconvert": {},
61+
"lab/api/workspaces": {"workspaces": []},
5862
"api/kernelspecs": {
5963
"default": "python3",
6064
"kernelspecs": {
@@ -84,32 +88,32 @@ class JyveExporter(HTMLExporter):
8488
{
8589
"buildAvailable": "False",
8690
"buildCheck": "False",
91+
"quit_button": "False",
8792
"token": "",
8893
"devMode": "False",
8994
"terminalsAvailable": "False",
9095
"ignorePlugins": "[]",
9196
"serverRoot": "~/jyve",
9297
"mathjaxConfig": "TeX-AMS-MML_HTMLorMML-full,Safe",
93-
"mathjaxUrl": "../static/components/MathJax/MathJax.js",
98+
"mathjaxUrl": "static/components/MathJax/MathJax.js",
9499
"appName": "JupyterLab Beta",
95100
"appNamespace": "jupyterlab",
96101
"appSettingsDir": "~/jyve/settings",
97102
"appVersion": jupyterlab.__version__,
98103
"cacheFiles": "True",
99-
"pageUrl": "./lab",
100-
"publicUrl": "../lab/static/",
104+
"pageUrl": "/lab",
105+
"publicUrl": "/lab/static/",
101106
"schemasDir": "~/jyve/schemas/",
102-
"settingsUrl": "../lab/api/settings/",
107+
"settingsUrl": "/lab/api/settings/",
103108
"staticDir": "~/jyve/static",
104109
"templatesDir": "~/jyve/templates",
105110
"themesDir": "~/jyve/themes/",
106111
"themesUrl": "/lab/api/themes/",
107-
"treeUrl": "../lab/tree/",
112+
"treeUrl": "/lab/tree/",
108113
"userSettingsDir": "~/jyve/lab/user-settings",
109114
"workspacesDir": "~/jyve/lab/workspaces",
110-
"workspacesUrl": "../lab/workspaces/",
111-
"workspacesApiUrl": "../api/workspaces/",
112-
"baseUrl": "../",
115+
"workspacesUrl": "/lab/workspaces/",
116+
"workspacesApiUrl": "/api/workspaces/",
113117
"wsUrl": "",
114118
"jyveOffline": True,
115119
},
@@ -291,9 +295,26 @@ def fix_index(self, output_root):
291295

292296
list(output_root.glob("lab*token*"))[0].rename(index)
293297

298+
# we dynamically update the script tag with the proper base url
299+
script_content = """
300+
<script type="text/javascript">;(function(){
301+
var config = %s;
302+
config.baseUrl = window.location.pathname.replace(/lab\/$/, '');
303+
config.mathjaxUrl = config.baseUrl + config.mathjaxUrl;
304+
var script = document.createElement("script");
305+
script.id = "jupyter-config-data";
306+
script.type = "application/json";
307+
script.textContent = JSON.stringify(config);
308+
debugger;
309+
document.head.appendChild(script);
310+
})();</script>
311+
""" % json.dumps(
312+
self.jupyter_config_data, indent=2
313+
)
314+
294315
new_idx = re.sub(
295316
'(<script.*?id="jupyter-config-data".*?>).*?(</script>)',
296-
"\\1\n{}\n</script>".format(json.dumps(self.jupyter_config_data, indent=2)),
317+
script_content,
297318
index.read_text(),
298319
flags=re.M | re.S,
299320
)
@@ -354,5 +375,5 @@ def fake_home(self, output_root):
354375
index = Path(output_root) / "index.html"
355376
index.write_text(
356377
"""<!DOCTYPE html>\n"""
357-
"""<meta http-equiv="refresh" content="0; URL=./lab" />"""
378+
"""<meta http-equiv="refresh" content="0; URL=./lab/" />"""
358379
)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
"bootstrap": "jlpm --no-optional && jlpm clean && jlpm lint && jlpm lerna bootstrap && jlpm build && jlpm lab:link",
3838
"build": "jlpm build:core && jlpm build:js && jlpm build:kyrnel && jlpm build:lyb",
3939
"build:core": "lerna run build --scope '@deathbeds/jyve' --stream",
40-
"build:demo": "mkdir -p index_files _demo && rm -rf index_files/* && jupyter nbconvert --to=jyve index.ipynb --JyveExporter.extra_contents='[\"notebooks/*.ipynb\"]' && cp -r index_files/* _demo/",
40+
"build:demo": "mkdir -p index_files demo && rm -rf {index_files,demo}/* && jupyter nbconvert --to=jyve index.ipynb --JyveExporter.extra_contents='[\"notebooks/*.ipynb\"]' && cp -r index_files/* demo/",
4141
"build:js": "lerna run build --scope '@deathbeds/jyve-kyrnel-js-unsafe' --stream",
4242
"build:kyrnel": "lerna run build --scope '@deathbeds/jyve-kyrnel-*' --stream",
4343
"build:lyb": "lerna run build --scope '@deathbeds/jyve-lyb-*' --stream",
4444
"clean": "lerna run --parallel clean --stream",
45+
"demo": "jlpm build:demo && jlpm demo:serve",
46+
"demo:serve": "python scripts/serve_demo.py",
4547
"lab:dupes": "cd $CONDA_PREFIX/share/jupyter/lab/staging/build && webpack-stats-duplicates stats.json",
4648
"lab:link": "lerna exec --concurrency 1 --stream -- jupyter labextension link . --no-build --debug",
4749
"lab:stats": "cd $CONDA_PREFIX/share/jupyter/lab/staging && mkdir -p build && ./node_modules/.bin/webpack --config webpack.prod.config.js --profile --json > stats.json && mv stats.json build/",
File renamed without changes.

scripts/serve_demo.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
from pathlib import Path
3+
from tempfile import TemporaryDirectory
4+
5+
from OpenSSL import crypto
6+
7+
from tornado import web, ioloop
8+
9+
10+
PORT = 8443
11+
12+
13+
def make_ssl_options(cert_path):
14+
# create a key pair
15+
key = crypto.PKey()
16+
key.generate_key(crypto.TYPE_RSA, 1024)
17+
18+
# create a self-signed cert
19+
cert = crypto.X509()
20+
subj = cert.get_subject()
21+
subj.C = "US"
22+
subj.ST = "GA"
23+
subj.L = "ATL"
24+
subj.O = "Dead Pixels Collection"
25+
subj.OU = "deathbeds"
26+
subj.CN = "jyve"
27+
28+
cert.set_serial_number(1000)
29+
cert.gmtime_adj_notBefore(0)
30+
cert.gmtime_adj_notAfter(10 * 365 * 24 * 60 * 60)
31+
cert.set_issuer(subj)
32+
cert.set_pubkey(key)
33+
cert.sign(key, "sha256")
34+
35+
certfile = cert_path / "jyve.crt"
36+
keyfile = cert_path / "jyve.key"
37+
38+
certfile.write_bytes(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
39+
keyfile.write_bytes(crypto.dump_privatekey(crypto.FILETYPE_PEM, key))
40+
41+
return dict(
42+
certfile=str(certfile),
43+
keyfile=str(keyfile)
44+
)
45+
46+
47+
class IndexHandler(web.StaticFileHandler):
48+
def parse_url_path(self, url_path):
49+
if not url_path or url_path[-1] == "/":
50+
url_path += "index.html"
51+
return url_path
52+
53+
54+
if __name__ == "__main__":
55+
with TemporaryDirectory() as td:
56+
web.Application(
57+
handlers=[
58+
(r"^/d/e/m/o/(.*)", IndexHandler,
59+
dict(path="demo"))
60+
],
61+
debug=True
62+
).listen(PORT, ssl_options=make_ssl_options(Path(td)))
63+
print(f"Listening on https://localhost:{PORT}/d/e/m/o/")
64+
ioloop.IOLoop.instance().start()

tests/resources/Jyve.robot

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Library Process
44
Resource Lab.robot
55

66
*** Variables ***
7-
${DEMO_CMD} ./scripts/demo.sh
8-
${HTTP_CMD} python -m http.server --bind 127.0.0.1 19980
9-
${DEMO_URL} http://127.0.0.1:19980/
7+
${DEMO_CMD} ./scripts/build_demo.sh
8+
${HTTPS_CMD} python ./scripts/serve_demo.py
9+
${DEMO_URL} https://127.0.0.1:8443/d/e/m/o/
1010

1111
*** Keywords ***
1212
Rebuild the Jyve Demo
@@ -18,7 +18,8 @@ Rebuild the Jyve Demo
1818

1919
Start the Jyve Demo
2020
[Documentation] Serve the static demo
21-
Start Process ${HTTP_CMD} shell=true cwd=demo
21+
Start Process ${HTTPS_CMD} shell=true stderr=STDOUT stdout=${OUTPUT_DIR}/demo.log
22+
2223

2324
Open the Jyve Demo with
2425
[Arguments] ${browser}

tests/resources/Lab.robot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Library OperatingSystem
77
*** Variables ***
88
${CELL_CSS} .jp-Notebook .jp-Cell:last-of-type .jp-InputArea-editor .CodeMirror
99
${TOKEN} hopelesslyinsecure
10-
${LAB_CMD} jupyter-lab --no-browser --NotebookApp.token=${TOKEN} --port 18888
10+
${LAB_CMD} jupyter-lab --no-browser --NotebookApp.token=${TOKEN} --port 18888 --notebook-dir ${OUTPUT_DIR}${/}notebooks
1111
${LAB_URL} http://localhost:18888/lab?token=${TOKEN}
1212
${SPLASH_ID} jupyterlab-splash
1313
${SPINNER} css:.jp-Spinner
@@ -35,6 +35,7 @@ Launch a new
3535

3636
Start JupyterLab
3737
[Documentation] Start a Jupyter Notebook Server with JupyterLab
38+
Create Directory ${OUTPUT_DIR}${/}notebooks
3839
Start Process ${LAB_CMD} shell=true stderr=STDOUT stdout=${OUTPUT_DIR}/lab.log
3940

4041
Click JupyterLab Menu

0 commit comments

Comments
 (0)