From 4feeff1bb948c18131c2aed9a81b94b208b6c823 Mon Sep 17 00:00:00 2001 From: Tyler Smalley Date: Tue, 13 Sep 2016 12:20:22 -0700 Subject: [PATCH] Upgrades Hapi to 14.2.0 As of Node 6, crypto.pbkdf emits a deprecation warning when the digest isn't explicily set. Under certain conditions we are seeing this warning from Hapi's dependency Iron. Iron resolved this issue as of 4.0.4, which was introduced into Hapi as of 14.0.0. Node deprecation: https://github.com/nodejs/node/pull/4047/commits/8e8959d3ee0bfe48b5f4d239e7f031a1a27708f0 Iron's resolution: https://github.com/hueniverse/iron/pull/43/commits/9e0a1ef5927c707fc79c5f2fa8c69a4b956897a4 As of Hapi v9, they have removed three build-in plugins from the core which we rely on inert (files and directories), vision (view templates), and h2o2 (proxy). https://github.com/hapijs/hapi/issues/2682 Signed-off-by: Tyler Smalley --- package.json | 5 +++- src/cli/cluster/base_path_proxy.js | 3 +++ .../elasticsearch/lib/__tests__/routes.js | 23 ++++++++----------- src/optimize/lazy/lazy_server.js | 5 +++- src/server/http/index.js | 5 +++- src/server/http/register_hapi_plugins.js | 16 +++++++++++++ src/server/kbn_server.js | 1 - 7 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 src/server/http/register_hapi_plugins.js diff --git a/package.json b/package.json index cd314b5fdfa39..e20446f3b2bf9 100644 --- a/package.json +++ b/package.json @@ -114,10 +114,12 @@ "glob-all": "3.0.1", "good-squeeze": "2.1.0", "gridster": "0.5.6", - "hapi": "8.8.1", + "h2o2": "5.1.1", + "hapi": "14.2.0", "highland": "2.7.2", "httpolyglot": "0.1.1", "imports-loader": "0.6.4", + "inert": "4.0.2", "jade": "1.11.0", "jade-loader": "0.7.1", "joi": "6.6.1", @@ -154,6 +156,7 @@ "trunc-text": "1.0.2", "url-loader": "0.5.6", "validate-npm-package-name": "2.2.2", + "vision": "4.1.0", "webpack": "1.12.15", "webpack-directory-name-as-main": "1.0.0", "whatwg-fetch": "0.9.0", diff --git a/src/cli/cluster/base_path_proxy.js b/src/cli/cluster/base_path_proxy.js index 803afeffdc36e..252cc40442778 100644 --- a/src/cli/cluster/base_path_proxy.js +++ b/src/cli/cluster/base_path_proxy.js @@ -8,6 +8,7 @@ import { readFileSync } from 'fs'; import Config from '../../server/config/config'; import setupConnection from '../../server/http/setup_connection'; +import registerHapiPlugins from '../../server/http/register_hapi_plugins'; import setupLogging from '../../server/logging'; import { DEV_SSL_CERT_PATH } from '../dev_ssl'; @@ -44,6 +45,8 @@ export default class BasePathProxy { setupLogging(null, this.server, config); setupConnection(null, this.server, config); + registerHapiPlugins(null, this.server, config); + this.setupRoutes(); } diff --git a/src/core_plugins/elasticsearch/lib/__tests__/routes.js b/src/core_plugins/elasticsearch/lib/__tests__/routes.js index 1c4397fbe6ae2..74bee4e71532b 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/routes.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/routes.js @@ -30,12 +30,11 @@ describe('plugins/elasticsearch', function () { return kbnServer.close(); }); - function testRoute(options) { + function testRoute(options, statusCode = 200) { if (typeof options.payload === 'object') { options.payload = JSON.stringify(options.payload); } - const statusCode = options.statusCode || 200; describe(format('%s %s', options.method, options.url), function () { it('should should return ' + statusCode, function (done) { kbnTestServer.makeRequest(kbnServer, options, function (res) { @@ -62,21 +61,18 @@ describe('plugins/elasticsearch', function () { testRoute({ method: 'POST', - url: '/elasticsearch/.kibana', - statusCode: 405 - }); + url: '/elasticsearch/.kibana' + }, 405); testRoute({ method: 'PUT', - url: '/elasticsearch/.kibana', - statusCode: 405 - }); + url: '/elasticsearch/.kibana' + }, 405); testRoute({ method: 'DELETE', - url: '/elasticsearch/.kibana', - statusCode: 405 - }); + url: '/elasticsearch/.kibana' + }, 405); testRoute({ method: 'GET', @@ -86,9 +82,8 @@ describe('plugins/elasticsearch', function () { testRoute({ method: 'POST', url: '/elasticsearch/.kibana/_bulk', - payload: '{}', - statusCode: 400 - }); + payload: '{}' + }, 400); testRoute({ method: 'POST', diff --git a/src/optimize/lazy/lazy_server.js b/src/optimize/lazy/lazy_server.js index 2f9fc1cde81bf..0b6440645dec4 100644 --- a/src/optimize/lazy/lazy_server.js +++ b/src/optimize/lazy/lazy_server.js @@ -2,12 +2,15 @@ import Boom from 'boom'; import { Server } from 'hapi'; import { fromNode } from 'bluebird'; - +import registerHapiPlugins from '../../server/http/register_hapi_plugins'; module.exports = class LazyServer { constructor(host, port, optimizer) { this.optimizer = optimizer; this.server = new Server(); + + registerHapiPlugins(null, this.server); + this.server.connection({ host: host, port: port diff --git a/src/server/http/index.js b/src/server/http/index.js index 46e19e07aa4d6..f8d9df1512cd7 100644 --- a/src/server/http/index.js +++ b/src/server/http/index.js @@ -4,15 +4,18 @@ import _ from 'lodash'; import fs from 'fs'; import Boom from 'boom'; import Hapi from 'hapi'; +import HapiTemplates from 'vision'; +import HapiStaticFiles from 'inert'; +import HapiProxy from 'h2o2'; import getDefaultRoute from './get_default_route'; import versionCheckMixin from './version_check'; module.exports = async function (kbnServer, server, config) { - server = kbnServer.server = new Hapi.Server(); const shortUrlLookup = require('./short_url_lookup')(server); + await kbnServer.mixin(require('./register_hapi_plugins')); await kbnServer.mixin(require('./setup_connection')); // provide a simple way to expose static directories diff --git a/src/server/http/register_hapi_plugins.js b/src/server/http/register_hapi_plugins.js new file mode 100644 index 0000000000000..395beb0d37a6c --- /dev/null +++ b/src/server/http/register_hapi_plugins.js @@ -0,0 +1,16 @@ +import HapiTemplates from 'vision'; +import HapiStaticFiles from 'inert'; +import HapiProxy from 'h2o2'; +import { fromNode } from 'bluebird'; + +const plugins = [HapiTemplates, HapiStaticFiles, HapiProxy]; + +async function registerPlugins(server) { + await fromNode(cb => { + server.register(plugins, cb); + }); +} + +export default function (kbnServer, server, config) { + registerPlugins(server); +} diff --git a/src/server/kbn_server.js b/src/server/kbn_server.js index 8ad9d9c0709d8..96ece10cc93df 100644 --- a/src/server/kbn_server.js +++ b/src/server/kbn_server.js @@ -1,4 +1,3 @@ -import Hapi from 'hapi'; import { constant, once, compact, flatten } from 'lodash'; import { promisify, resolve, fromNode } from 'bluebird'; import { isWorker } from 'cluster';