From 900787379f9631158b75f48bb354f4fe565638f1 Mon Sep 17 00:00:00 2001 From: joe fleming Date: Mon, 22 Oct 2018 13:21:28 -0700 Subject: [PATCH] fix: use basepath from state for socket path --- .../canvas/public/components/app/index.js | 20 +++++++++++++++---- x-pack/plugins/canvas/public/socket.js | 4 +--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/canvas/public/components/app/index.js b/x-pack/plugins/canvas/public/components/app/index.js index 6c401b61aa0eb7..2c4d1f6e9f808f 100644 --- a/x-pack/plugins/canvas/public/components/app/index.js +++ b/x-pack/plugins/canvas/public/components/app/index.js @@ -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'; @@ -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 @@ -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, diff --git a/x-pack/plugins/canvas/public/socket.js b/x-pack/plugins/canvas/public/socket.js index 8e93bdf175ecb8..a96320c8e0f7e4 100644 --- a/x-pack/plugins/canvas/public/socket.js +++ b/x-pack/plugins/canvas/public/socket.js @@ -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', () => {