diff --git a/src/api/websocket-api.js b/src/api/websocket-api.js index 73b2dd4..a5ceba1 100644 --- a/src/api/websocket-api.js +++ b/src/api/websocket-api.js @@ -35,11 +35,16 @@ class WebsocketAPI { } getURL(node) { - if (node.relativeEndpoint) { - return 'ws://' + window.location.host + '/' + node.endpoint; - } else { - return 'ws://' + node.endpoint; - } + // create an anchor element (note: no need to append this element to the document) + var link = document.createElement('a'); + link.href = node.endpoint; + + if (link.protocol === 'https:') + link.protocol = 'wss:'; + else + link.protocol = 'ws:'; + + return link.href; } } diff --git a/src/components/dialog/edit-node.js b/src/components/dialog/edit-node.js index 19b2f8e..beba460 100644 --- a/src/components/dialog/edit-node.js +++ b/src/components/dialog/edit-node.js @@ -20,7 +20,7 @@ ******************************************************************************/ import React from 'react'; -import { FormGroup, FormControl, ControlLabel, Checkbox } from 'react-bootstrap'; +import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import Dialog from './dialog'; @@ -35,7 +35,6 @@ class NewNodeDialog extends React.Component { endpoint: '', config: {}, simulators: [], - relativeEndpoint: false, _id: '' }; } @@ -59,7 +58,7 @@ class NewNodeDialog extends React.Component { } resetState() { - this.setState({ name: this.props.node.name, endpoint: this.props.node.endpoint, config: this.props.node.config, simulators: this.props.node.simulators, _id: this.props.node._id, relativeEndpoint: this.props.node.relativeEndpoint }); + this.setState({ name: this.props.node.name, endpoint: this.props.node.endpoint, config: this.props.node.config, simulators: this.props.node.simulators, _id: this.props.node._id }); } validateForm(target) { @@ -96,9 +95,6 @@ class NewNodeDialog extends React.Component { this.handleChange(e)} /> - - this.handleChange(e)}>Relative Endpoint - ); diff --git a/src/components/dialog/import-node.js b/src/components/dialog/import-node.js index 1f35129..5401745 100644 --- a/src/components/dialog/import-node.js +++ b/src/components/dialog/import-node.js @@ -20,7 +20,7 @@ ******************************************************************************/ import React from 'react'; -import { FormGroup, FormControl, ControlLabel, Checkbox } from 'react-bootstrap'; +import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import Dialog from './dialog'; @@ -34,8 +34,7 @@ class ImportNodeDialog extends React.Component { this.state = { name: '', endpoint: '', - simulators: [], - relativeEndpoint: false + simulators: [] }; } @@ -56,7 +55,7 @@ class ImportNodeDialog extends React.Component { } resetState() { - this.setState({ name: '', endpoint: '', relativeEndpoint: false }); + this.setState({ name: '', endpoint: '' }); this.imported = false; } @@ -76,7 +75,7 @@ class ImportNodeDialog extends React.Component { // read simulator const node = JSON.parse(event.target.result); self.imported = true; - self.setState({ name: node.name, endpoint: node.endpoint, simulators: node.simulators, relativeEndpoint: node.relativeEndpoint }); + self.setState({ name: node.name, endpoint: node.endpoint, simulators: node.simulators }); }; reader.readAsText(file); @@ -121,9 +120,6 @@ class ImportNodeDialog extends React.Component { this.handleChange(e)} /> - - this.handleChange(e)}>Relative Endpoint - ); diff --git a/src/components/dialog/new-node.js b/src/components/dialog/new-node.js index b0b4357..aedd1ee 100644 --- a/src/components/dialog/new-node.js +++ b/src/components/dialog/new-node.js @@ -20,7 +20,7 @@ ******************************************************************************/ import React from 'react'; -import { FormGroup, FormControl, ControlLabel, Checkbox } from 'react-bootstrap'; +import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import Dialog from './dialog'; @@ -34,8 +34,7 @@ class NewNodeDialog extends React.Component { name: '', endpoint: '', config: {}, - simulators: [], - relativeEndpoint: false + simulators: [] }; } @@ -58,7 +57,7 @@ class NewNodeDialog extends React.Component { } resetState() { - this.setState({ name: '', endpoint: '', config: {}, simulators: [], relativeEndpoint: false }); + this.setState({ name: '', endpoint: '', config: {}, simulators: [] }); } validateForm(target) { @@ -95,9 +94,6 @@ class NewNodeDialog extends React.Component { this.handleChange(e)} /> - - this.handleChange(e)}>Relative Endpoint - ); diff --git a/src/data-managers/nodes-data-manager.js b/src/data-managers/nodes-data-manager.js index 0a02419..2374a1f 100644 --- a/src/data-managers/nodes-data-manager.js +++ b/src/data-managers/nodes-data-manager.js @@ -29,11 +29,12 @@ class NodesDataManager extends RestDataManager { } getURL(node) { - if (node.relativeEndpoint) { - return 'http://' + window.location.host + '/' + node.endpoint + '/api/v1'; - } else { - return 'http://' + node.endpoint + '/api/v1'; - } + // create an anchor element (note: no need to append this element to the document) + var link = document.createElement('a'); + link.href = node.endpoint; + link.pathname = link.pathname + 'api/v1'; + + return link.href; } getSimulators(node) {