Hi,

I am coming up against an issue with being able to set the NotebookApp 
server to accept the two following headers during a CORS kernel API 
request: X-XSRFToken and Content-Type.

I am looking for help and direction.


*Background*
I'm building a tool written in Angular that makes use of the typescript npm 
package @jupyterlab/services. I am basing what I am doing off of the 
example found here:
https://github.com/jupyterlab/jupyterlab/blob/master/packages/services/examples/browser/main.py

This works great for deployment and bundling into a browser, but I would 
like my webpack development server to also be able to access the notebook 
services api. The webpack dev server is running on a different port so all 
of the CORS issues now come into play. There are sufficient settings that 
can be passed to the NotebookApp that allows me to have the app accept 
basic API requests from my webpack dev server. These settings that I pass 
are the following:

password='', token='', port=8888, 
ip='localhost', port_retries=0, 
allow_origin='http://localhost:5000', open_browser=False, 
tornado_settings={'debug':True}

The webpack development server can communicate to the notebook services 
however the notebook service does not accept the api requests of kernel 
creation because the following two headers need to be allowed:
X-XSRFToken and Content-Type

*Current Hacky Solution*
I can get the webpack dev server to talk to a kernel by swapping out 
NotebookApp with KernelGatewayApp from the jupyter_kernel_gateway package. 
Via trial and error I determined that calling the kernelgateway app in the 
following way lets me access the kernel from my webpack dev server:

jupyter kernelgateway --KernelGatewayApp.allow_origin='http://localhost:5000
' --KernelGatewayApp.allow_headers='X-XSRFToken,Content-Type' 
--JupyterWebsocketPersonality.list_kernels=True

Since kernelgateway does not have a "tornado_settings" override I have also 
overwritten the init_webapp class so that I can pass debug=True into the 
tornado.web.Application.

This all works, but it is hacky, brittle, and I am no longer running my dev 
environment using the same class as my production.

*Ideal solution*
The notebook app already has an allow_origin parameter but without also 
having an allow_headers parameter I can't seem to access the kernel from 
another origin. Is there a way to set allow_headers within NotebookApp 
similar to what I can do within KernelGatewayApp?

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/27f620d8-5ad8-43a8-ae50-99f312c8b016%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to