Permalink
Browse files

add notebook proxy extension

  • Loading branch information...
minrk committed May 10, 2018
1 parent d9c0732 commit af8749b96188d0caada80cc3c35fdae9c53de613
Showing with 53 additions and 0 deletions.
  1. +5 −0 Dockerfile
  2. +47 −0 jupyter_notebook_config.py
  3. +1 −0 requirements.txt
@@ -13,3 +13,8 @@ RUN git clone --depth 1 https://github.com/stencila/stencila.git ${STENCILA_DIR}
RUN npm install

WORKDIR ${HOME}
ADD requirements.txt /tmp/requirements.txt
RUN pip install --no-cache -r /tmp/requirements.txt

RUN test -d ${HOME}/.jupyter/ || mkdir ${HOME}/.jupyter/
ADD jupyter_notebook_config.py ${HOME}/.jupyter/jupyter_notebook_config.py
@@ -0,0 +1,47 @@
import pipes
import sys

from nbserverproxy.handlers import SuperviseAndProxyHandler

# define our proxy handler for proxying the application

class StencilaProxyHandler(SuperviseAndProxyHandler):

name = 'stencila'

def get_cmd(self):
cmd = ' '.join(map(pipes.quote, [
'node',
'make',
'-w',
'-s',
'-d',
self.state['notebook_dir'],
]))
return [
'sh', '-c', 'cd "$STENCILA_DIR"; ' + cmd,
]


def add_handlers(app):
app.web_app.add_handlers('.*', [
(
app.base_url + 'stencila/(.*)',
StencilaProxyHandler,
dict(state=dict(
port=4000,
notebook_dir=app.notebook_dir,
)),
),
])


# fake a module to load the proxy handler as an extension
module_name = '_myproxymod'
import types
mod = types.ModuleType(module_name)
sys.modules[module_name] = mod
mod.load_jupyter_server_extension = add_handlers
c.NotebookApp.nbserver_extensions.update({
module_name: True,
})
@@ -0,0 +1 @@
nbserverproxy

0 comments on commit af8749b

Please sign in to comment.