-
Notifications
You must be signed in to change notification settings - Fork 2
/
jupyter_server_config.py
54 lines (44 loc) · 1.77 KB
/
jupyter_server_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# See http://ipython.org/ipython-doc/1/interactive/public_server.html for more information.
# Configuration file for ipython-notebook.
import os
import psutil
c = get_config()
c.ServerApp.token = ''
c.ServerApp.password = ''
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.profile = u'default'
c.IPKernelApp.matplotlib = 'inline'
CORS_ORIGIN = ''
CORS_ORIGIN_HOSTNAME = ''
if os.environ['CORS_ORIGIN'] != 'none':
CORS_ORIGIN = os.environ.get('CORS_ORIGIN', '')
CORS_ORIGIN_HOSTNAME = CORS_ORIGIN.split('://')[1]
headers = {
'X-Frame-Options': 'ALLOWALL',
'Content-Security-Policy': """
default-src 'self' %(CORS_ORIGIN)s;
img-src 'self' %(CORS_ORIGIN)s;
connect-src 'self' %(WS_CORS_ORIGIN)s;
style-src 'unsafe-inline' 'self' %(CORS_ORIGIN)s;
script-src 'unsafe-inline' 'self' %(CORS_ORIGIN)s;
""" % {'CORS_ORIGIN': CORS_ORIGIN, 'WS_CORS_ORIGIN': 'ws://%s' % CORS_ORIGIN_HOSTNAME}
}
c.ServerApp.allow_origin = '*'
c.ServerApp.allow_credentials = True
c.ServerApp.base_url = '%s/ipython/' % os.environ.get('PROXY_PREFIX', '')
c.ServerApp.tornado_settings = {
'static_url_prefix': '%s/ipython/static/' % os.environ.get('PROXY_PREFIX', '')
}
if os.environ.get('NOTEBOOK_PASSWORD', 'none') != 'none':
c.ServerApp.password = os.environ['NOTEBOOK_PASSWORD']
del os.environ['NOTEBOOK_PASSWORD']
if CORS_ORIGIN:
c.ServerApp.allow_origin = CORS_ORIGIN
# monitor resource usage
c.ResourceUseDisplay.mem_limit = psutil.virtual_memory().total
c.ResourceUseDisplay.track_cpu_percent = True
c.ResourceUseDisplay.cpu_limit = os.cpu_count()
c.ServerApp.contents_manager_class = "jupytext.TextFileContentsManager"
c.ServerApp.tornado_settings['headers'] = headers