Skip to content

Commit

Permalink
fix: use basepath from state for socket path
Browse files Browse the repository at this point in the history
  • Loading branch information
w33ble committed Oct 22, 2018
1 parent 13ab4cd commit 9007873
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 16 additions & 4 deletions x-pack/plugins/canvas/public/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { connect } from 'react-redux';
import { compose, withProps } from 'recompose';
import { createSocket } from '../../socket';
import { initialize as initializeInterpreter } from '../../lib/interpreter';
import { getAppReady } from '../../state/selectors/app';
import { getAppReady, getBasePath } from '../../state/selectors/app';
import { appReady, appError } from '../../state/actions/app';
import { trackRouteChange } from './track_route_change';
import { App as Component } from './app';
Expand All @@ -19,13 +19,15 @@ const mapStateToProps = state => {

return {
appState: typeof appState === 'object' ? appState : { ready: appState },
basePath: getBasePath(state),
};
};

const mapDispatchToProps = dispatch => ({
setAppReady: async () => {
// TODO: the correct socket path should come from upstream, using the constant here is not ideal
setAppReady: basePath => async () => {
// initialize the socket and interpreter
createSocket();
createSocket(basePath);
await initializeInterpreter();

// set app state to ready
Expand All @@ -34,10 +36,20 @@ const mapDispatchToProps = dispatch => ({
setAppError: payload => dispatch(appError(payload)),
});

const mergeProps = (stateProps, dispatchProps, ownProps) => {
return {
...ownProps,
...stateProps,
...dispatchProps,
setAppReady: dispatchProps.setAppReady(stateProps.basePath),
};
};

export const App = compose(
connect(
mapStateToProps,
mapDispatchToProps
mapDispatchToProps,
mergeProps
),
withProps(() => ({
onRouteChange: trackRouteChange,
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/canvas/public/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';
import io from 'socket.io-client';
import { functionsRegistry } from '../common/lib/functions_registry';
import { loadBrowserPlugins } from './lib/load_browser_plugins';

let socket;

export function createSocket() {
const basePath = chrome.getBasePath();
export function createSocket(basePath) {
socket = io(undefined, { path: `${basePath}/socket.io` });

socket.on('getFunctionList', () => {
Expand Down

0 comments on commit 9007873

Please sign in to comment.