Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use basepath from state for socket path #24369

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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