kibana/x-pack/plugins/canvas/server/lib/get_request.js
Joe Fleming 0999ebf273 Fix: socket setup (#24550)
PR fixes issues with the socket connection.

- handle socket failures 
  - previously would either leave Canvas in an infinite loading state, or load the app even when it wouldn't function
- upgrade socket.io
- add headers to socket connection and modify auth connection
2018-11-02 10:39:36 -07:00

30 lines
861 B
JavaScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import boom from 'boom';
import { API_ROUTE } from '../../common/lib/constants';
export function getRequest(server, { headers }) {
const url = `${API_ROUTE}/ping`;
return server
.inject({
method: 'POST',
url,
headers,
})
.then(res => {
if (res.statusCode !== 200) {
if (process.env.NODE_ENV !== 'production') {
console.error(
new Error(`Auth request failed: [${res.statusCode}] ${res.result.message}`)
);
}
throw boom.unauthorized('Failed to authenticate socket connection');
}
return res.request;
});
}