restore websocket_url configurable

allows ws to be handled via separate proxies,
as appears to be the case on OpenShift and some other hosting services.
This commit is contained in:
MinRK 2014-06-23 15:27:59 -07:00
parent f3e599e0c4
commit 579f5101f0
5 changed files with 24 additions and 6 deletions

View File

@ -127,6 +127,10 @@ class IPythonHandler(AuthenticatedHandler):
@property
def base_url(self):
return self.settings.get('base_url', '/')
@property
def ws_url(self):
return self.settings.get('websocket_url', '')
#---------------------------------------------------------------
# Manager objects
@ -215,6 +219,7 @@ class IPythonHandler(AuthenticatedHandler):
def template_namespace(self):
return dict(
base_url=self.base_url,
ws_url=self.ws_url,
logged_in=self.logged_in,
login_available=self.login_available,
static_url=self.static_url,

View File

@ -172,6 +172,7 @@ class NotebookWebApplication(web.Application):
# IPython stuff
nbextensions_path = ipython_app.nbextensions_path,
websocket_url=ipython_app.websocket_url,
mathjax_url=ipython_app.mathjax_url,
config=ipython_app.config,
jinja2_env=env,
@ -512,6 +513,13 @@ class NotebookApp(BaseIPythonApplication):
def _nbextensions_path_default(self):
return [os.path.join(get_ipython_dir(), 'nbextensions')]
websocket_url = Unicode("", config=True,
help="""The base URL for websockets,
if it differs from the HTTP server (hint: it almost certainly doesn't).
Should be in the form of an HTTP origin: ws[s]://hostname[:port]
"""
)
mathjax_url = Unicode("", config=True,
help="""The url for MathJax.js."""
)

View File

@ -43,6 +43,7 @@ require([
var common_options = {
base_url : utils.get_body_data("baseUrl"),
ws_url : IPython.utils.get_body_data("wsUrl"),
notebook_path : utils.get_body_data("notebookPath"),
notebook_name : utils.get_body_data('notebookName')
};

View File

@ -23,6 +23,11 @@ define([
this.stdin_channel = null;
this.kernel_service_url = kernel_service_url;
this.name = name;
this.ws_url = IPython.utils.get_body_data("wsUrl");
if (!this.ws_url) {
// trailing 's' in https will become wss for secure web sockets
this.ws_url = location.protocol.replace('http', 'ws') + "//" + location.host;
}
this.running = false;
this.username = "username";
this.session_id = utils.uuid();
@ -122,8 +127,6 @@ define([
console.log("Kernel started: ", json.id);
this.running = true;
this.kernel_id = json.id;
// trailing 's' in https will become wss for secure web sockets
this.ws_host = location.protocol.replace('http', 'ws') + "//" + location.host;
this.kernel_url = utils.url_path_join(this.kernel_service_url, this.kernel_id);
this.start_channels();
};
@ -145,16 +148,16 @@ define([
Kernel.prototype.start_channels = function () {
var that = this;
this.stop_channels();
var ws_host_url = this.ws_host + this.kernel_url;
var ws_host_url = this.ws_url + this.kernel_url;
console.log("Starting WebSockets:", ws_host_url);
this.shell_channel = new this.WebSocket(
this.ws_host + utils.url_join_encode(this.kernel_url, "shell")
this.ws_url + utils.url_join_encode(this.kernel_url, "shell")
);
this.stdin_channel = new this.WebSocket(
this.ws_host + utils.url_join_encode(this.kernel_url, "stdin")
this.ws_url + utils.url_join_encode(this.kernel_url, "stdin")
);
this.iopub_channel = new this.WebSocket(
this.ws_host + utils.url_join_encode(this.kernel_url, "iopub")
this.ws_url + utils.url_join_encode(this.kernel_url, "iopub")
);
var already_called_onclose = false; // only alert once

View File

@ -24,6 +24,7 @@ window.mathjax_url = "{{mathjax_url}}";
data-project="{{project}}"
data-base-url="{{base_url}}"
data-ws-url="{{ws_url}}"
data-notebook-name="{{notebook_name}}"
data-notebook-path="{{notebook_path}}"
class="notebook_app"