Skip to content

Commit

Permalink
fix: handle basepath rewriting for socket connection
Browse files Browse the repository at this point in the history
kibana/elastic#16724 added a basepath rewrite to the kibana server, and any route that doesn't go through hapi needs to deal with it explicitly
  • Loading branch information
w33ble committed Mar 9, 2018
1 parent 5a7519b commit 3a407cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions __tests__/fixtures/kibana.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get from 'lodash';
import { get, has } from 'lodash';
import mockElasticsearch from './elasticsearch_plugin';

const config = {
Expand All @@ -18,9 +18,10 @@ export class Plugin {
elasticsearch: mockElasticsearch,
},
config: () => ({
get: (key) => get(config, key),
get: key => get(config, key),
has: key => has(config, key),
}),
route: (def) => this.routes.push(def),
route: def => this.routes.push(def),
};

const { init } = this.props;
Expand Down
8 changes: 7 additions & 1 deletion server/routes/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { typesRegistry } from '../../common/lib/types_registry';
import { getAuthHeader } from './get_auth/get_auth_header';

export function socketApi(server) {
const io = socket(server.listener);
const config = server.config();
const socketPathPrefix =
config.has('server.rewriteBasePath') && config.get('server.rewriteBasePath')
? config.get('server.basePath')
: '';
const socketPath = `${socketPathPrefix}/socket.io`;
const io = socket(server.listener, { path: socketPath });

io.on('connection', socket => {
console.log('User connected, attaching handlers');
Expand Down

0 comments on commit 3a407cf

Please sign in to comment.