diff --git a/app/assets/javascripts/editor/execution.js.erb b/app/assets/javascripts/editor/execution.js similarity index 88% rename from app/assets/javascripts/editor/execution.js.erb rename to app/assets/javascripts/editor/execution.js index eb0ff55a..8ac6df4d 100644 --- a/app/assets/javascripts/editor/execution.js.erb +++ b/app/assets/javascripts/editor/execution.js @@ -2,11 +2,11 @@ CodeOceanEditorWebsocket = { websocket: null, createSocketUrl: function(url) { - var sockURL = new URL(url, window.location); + const sockURL = new URL(url, window.location); // not needed any longer, we put it directly into the url: sockURL.pathname = url; - // sanitize socket protocol string, strip trailing slash and other malicious chars if they are there - sockURL.protocol = '<%= DockerClient.config['ws_client_protocol']&.match(/(\w+):*\/*/)&.to_a&.at(1) %>:'; + // replace `http` with `ws` for the WebSocket connection. This also works with `https` and `wss`. + sockURL.protocol = sockURL.protocol.replace("http", "ws"); // strip anchor if it is in the url sockURL.hash = ''; diff --git a/config/docker.yml.erb.ci b/config/docker.yml.erb.ci index e878ca2f..12415d0f 100644 --- a/config/docker.yml.erb.ci +++ b/config/docker.yml.erb.ci @@ -10,7 +10,6 @@ development: <<: *default host: tcp://127.0.0.1:2376 ws_host: ws://127.0.0.1:2376 #url to connect rails server to docker host - ws_client_protocol: 'ws:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> pool: location: http://localhost:7100 @@ -35,7 +34,6 @@ production: timeout: 60 workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> ws_host: ws://localhost:4243 #url to connect rails server to docker host - ws_client_protocol: 'wss:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) staging: <<: *default @@ -50,10 +48,8 @@ staging: timeout: 60 workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> ws_host: ws://localhost:4243 #url to connect rails server to docker host - ws_client_protocol: 'wss:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) test: <<: *default host: tcp://127.0.0.1:2376 workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> - ws_client_protocol: 'ws:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) diff --git a/config/docker.yml.erb.example b/config/docker.yml.erb.example index 2e5d2955..bb41db98 100644 --- a/config/docker.yml.erb.example +++ b/config/docker.yml.erb.example @@ -10,7 +10,6 @@ development: <<: *default host: tcp://127.0.0.1:2376 ws_host: ws://127.0.0.1:2376 #url to connect rails server to docker host - ws_client_protocol: 'ws:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> pool: active: true @@ -35,7 +34,6 @@ production: timeout: 60 workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> ws_host: ws://localhost:4243 #url to connect rails server to docker host - ws_client_protocol: 'wss:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) staging: <<: *default @@ -50,7 +48,6 @@ staging: timeout: 60 workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> ws_host: ws://localhost:4243 #url to connect rails server to docker host - ws_client_protocol: 'wss:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) test: <<: *default