Skip to content

Commit

Permalink
Make websocket path relative to Shiny page path
Browse files Browse the repository at this point in the history
This is necessary for proxy situations that don't override the
Shiny.createSocket function (so, not including Shiny Server,
but more like Nginx, HAProxy, and a future version of RStudio
Server).

Without the path being preserved, it's impossible for these
proxies to know that the URL should be forwarded to the host
and port that belongs to Shiny.
  • Loading branch information
jcheng5 committed Sep 20, 2013
1 parent 004b7c7 commit d377b04
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,16 @@
var self = this;

var createSocketFunc = exports.createSocket || function() {
var ws = new WebSocket('ws://' + window.location.host + '/websocket/');
var protocol = 'ws:';
if (window.location.protocol === 'https:')
protocol = 'wss:';

var defaultPath = window.location.pathname;
if (!/\/$/.test(defaultPath))
defaultPath += '/';
defaultPath += 'websocket/';

var ws = new WebSocket(protocol + '//' + window.location.host + defaultPath);
ws.binaryType = 'arraybuffer';
return ws;
};
Expand Down

0 comments on commit d377b04

Please sign in to comment.