I am trying to proxy JupyterLab via Node js. Everything works fine, but when I click on create any notebook. the request to /jupyterLab/api/contents/
is failing.
Below are a few details:
Node version - v9.4.0
JupyterLab version -
jupyter core : 4.6.3
jupyter-notebook : 5.7.9
qtconsole : 4.5.4
ipython : 5.8.0
ipykernel : 4.10.1
jupyter client : 5.3.4
jupyter lab : 0.33.12
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 4.4.0
traitlets : 4.3.3
Using the Express framework. [Ref https://expressjs.com/en/starter/generator.html ]
NodeJs proxy package - http-proxy-middleware [Ref https://www.npmjs.com/package/http-proxy-middleware ]
Node application is running at http://localhost:3001/
JupyterLab is running at http://localhost:8889/
Node Code
var express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
var app = express();
app.use('/jupyterLab/', createProxyMiddleware({
target : "http://localhost:8889/",
ws : true
}));
module.exports = app;
JupyterLab configuration
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8889
c.NotebookApp.base_url = '/jupyterLab/'
c.NotebookApp.token = ''
c.NotebookApp.notebook_dir = "D:jupyterLab"
c.NotebookApp.allow_origin = '*'
c.NotebookApp.tornado_settings = {
'headers': {
'Content-Security-Policy': "frame-ancestors 'self' http://127.0.0.1:3001/ http://127.0.0.1:3001/* http://localhost:3001/ http://localhost:3001/*",
}
}
HTML - Method 1
<!-- Without proxy, it works perfectly fine. But Node isn't involved here. -->
<iframe
src = "http://localhost:8889/jupyterLab/"
height = "400px"
width = "100%"
></iframe>
**HTML - Method 2 ** <- Target.
<!-- With proxy, Works fine, but when we click on Notebook, an API call happens, which stays in pending state for 2-4 min and then fails. -->
<iframe
src = "/jupyterLab/"
height = "400px"
width = "100%"
></iframe>