mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* Remove some unused server.decorate calls * Stop using '.mixin' in several places
This commit is contained in:
parent
ea7df636a9
commit
18158346f5
15 changed files with 37 additions and 69 deletions
|
@ -6,9 +6,9 @@ import { Agent as HttpsAgent } from 'https';
|
|||
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 { setupConnection } from '../../server/http/setup_connection';
|
||||
import { registerHapiPlugins } from '../../server/http/register_hapi_plugins';
|
||||
import { setupLogging } from '../../server/logging';
|
||||
import { transformDeprecations } from '../../server/config/transform_deprecations';
|
||||
|
||||
const alphabet = 'abcdefghijklmnopqrztuvwxyz'.split('');
|
||||
|
@ -43,9 +43,9 @@ export default class BasePathProxy {
|
|||
const ONE_GIGABYTE = 1024 * 1024 * 1024;
|
||||
config.set('server.maxPayloadBytes', ONE_GIGABYTE);
|
||||
|
||||
setupLogging(null, this.server, config);
|
||||
setupConnection(null, this.server, config);
|
||||
registerHapiPlugins(null, this.server, config);
|
||||
setupLogging(this.server, config);
|
||||
setupConnection(this.server, config);
|
||||
registerHapiPlugins(this.server, config);
|
||||
|
||||
this.setupRoutes();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
import { Server } from 'hapi';
|
||||
import { fromNode } from 'bluebird';
|
||||
import registerHapiPlugins from '../../server/http/register_hapi_plugins';
|
||||
import { registerHapiPlugins } from '../../server/http/register_hapi_plugins';
|
||||
|
||||
export default class WatchServer {
|
||||
constructor(host, port, basePath, optimizer) {
|
||||
|
@ -9,7 +9,7 @@ export default class WatchServer {
|
|||
this.optimizer = optimizer;
|
||||
this.server = new Server();
|
||||
|
||||
registerHapiPlugins(null, this.server);
|
||||
registerHapiPlugins(this.server);
|
||||
|
||||
this.server.connection({
|
||||
host: host,
|
||||
|
|
|
@ -17,7 +17,7 @@ describe('server / setup_base_path_rewrite', () => {
|
|||
|
||||
const server = new Server();
|
||||
server.connection({ port: 0 });
|
||||
setupBasePathRewrite({}, server, config);
|
||||
setupBasePathRewrite(server, config);
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import shortUrlLookupProvider from '../short_url_lookup';
|
||||
import { shortUrlLookupProvider } from '../short_url_lookup';
|
||||
import { SavedObjectsClient } from '../../saved_objects/client';
|
||||
|
||||
describe('shortUrlLookupProvider', () => {
|
||||
|
|
|
@ -4,24 +4,25 @@ import _ from 'lodash';
|
|||
import Boom from 'boom';
|
||||
import Hapi from 'hapi';
|
||||
import getDefaultRoute from './get_default_route';
|
||||
import versionCheckMixin from './version_check';
|
||||
import { setupVersionCheck } from './version_check';
|
||||
import { handleShortUrlError } from './short_url_error';
|
||||
import { shortUrlAssertValid } from './short_url_assert_valid';
|
||||
import shortUrlLookupProvider from './short_url_lookup';
|
||||
import setupConnectionMixin from './setup_connection';
|
||||
import setupRedirectMixin from './setup_redirect_server';
|
||||
import registerHapiPluginsMixin from './register_hapi_plugins';
|
||||
import { shortUrlLookupProvider } from './short_url_lookup';
|
||||
import { setupConnection } from './setup_connection';
|
||||
import { setupRedirectServer } from './setup_redirect_server';
|
||||
import { registerHapiPlugins } from './register_hapi_plugins';
|
||||
import { setupBasePathRewrite } from './setup_base_path_rewrite';
|
||||
import xsrfMixin from './xsrf';
|
||||
import { setupXsrf } from './xsrf';
|
||||
|
||||
export default async function (kbnServer, server, config) {
|
||||
server = kbnServer.server = new Hapi.Server();
|
||||
|
||||
const shortUrlLookup = shortUrlLookupProvider(server);
|
||||
await kbnServer.mixin(setupConnectionMixin);
|
||||
await kbnServer.mixin(setupBasePathRewrite);
|
||||
await kbnServer.mixin(setupRedirectMixin);
|
||||
await kbnServer.mixin(registerHapiPluginsMixin);
|
||||
|
||||
setupConnection(server, config);
|
||||
setupBasePathRewrite(server, config);
|
||||
await setupRedirectServer(config);
|
||||
registerHapiPlugins(server);
|
||||
|
||||
// provide a simple way to expose static directories
|
||||
server.decorate('server', 'exposeStaticDir', function (routePath, dirPath) {
|
||||
|
@ -39,18 +40,6 @@ export default async function (kbnServer, server, config) {
|
|||
});
|
||||
});
|
||||
|
||||
// provide a simple way to expose static files
|
||||
server.decorate('server', 'exposeStaticFile', function (routePath, filePath) {
|
||||
this.route({
|
||||
path: routePath,
|
||||
method: 'GET',
|
||||
handler: {
|
||||
file: filePath
|
||||
},
|
||||
config: { auth: false }
|
||||
});
|
||||
});
|
||||
|
||||
// helper for creating view managers for servers
|
||||
server.decorate('server', 'setupViews', function (path, engines) {
|
||||
this.views({
|
||||
|
@ -60,19 +49,6 @@ export default async function (kbnServer, server, config) {
|
|||
});
|
||||
});
|
||||
|
||||
server.decorate('server', 'redirectToSlash', function (route) {
|
||||
this.route({
|
||||
path: route,
|
||||
method: 'GET',
|
||||
handler: function (req, reply) {
|
||||
return reply.redirect(format({
|
||||
search: req.url.search,
|
||||
pathname: req.url.pathname + '/',
|
||||
}));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// attach the app name to the server, so we can be sure we are actually talking to kibana
|
||||
server.ext('onPreResponse', function (req, reply) {
|
||||
const response = req.response;
|
||||
|
@ -168,7 +144,6 @@ export default async function (kbnServer, server, config) {
|
|||
server.exposeStaticDir('/ui/fonts/{path*}', resolve(__dirname, '../../ui/public/assets/fonts'));
|
||||
server.exposeStaticDir('/ui/favicons/{path*}', resolve(__dirname, '../../ui/public/assets/favicons'));
|
||||
|
||||
kbnServer.mixin(versionCheckMixin);
|
||||
|
||||
return kbnServer.mixin(xsrfMixin);
|
||||
setupVersionCheck(server, config);
|
||||
setupXsrf(server, config);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ async function registerPlugins(server) {
|
|||
});
|
||||
}
|
||||
|
||||
export default function (kbnServer, server) {
|
||||
export function registerHapiPlugins(server) {
|
||||
registerPlugins(server);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import Boom from 'boom';
|
|||
|
||||
import { modifyUrl } from '../../utils';
|
||||
|
||||
export function setupBasePathRewrite(kbnServer, server, config) {
|
||||
export function setupBasePathRewrite(server, config) {
|
||||
const basePath = config.get('server.basePath');
|
||||
const rewriteBasePath = config.get('server.rewriteBasePath');
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import { readFileSync } from 'fs';
|
||||
import secureOptions from './secure_options';
|
||||
|
||||
export default function (kbnServer, server, config) {
|
||||
// this mixin is used outside of the kbn server, so it MUST work without a full kbnServer object.
|
||||
kbnServer = null;
|
||||
|
||||
export function setupConnection(server, config) {
|
||||
const host = config.get('server.host');
|
||||
const port = config.get('server.port');
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import Hapi from 'hapi';
|
|||
|
||||
// If a redirect port is specified, we start an http server at this port and
|
||||
// redirect all requests to the ssl port.
|
||||
export default async function (kbnServer, server, config) {
|
||||
export async function setupRedirectServer(config) {
|
||||
const isSslEnabled = config.get('server.ssl.enabled');
|
||||
const portToRedirectFrom = config.get('server.ssl.redirectHttpFromPort');
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import crypto from 'crypto';
|
||||
import { get } from 'lodash';
|
||||
|
||||
export default function (server) {
|
||||
export function shortUrlLookupProvider(server) {
|
||||
async function updateMetadata(doc, req) {
|
||||
try {
|
||||
await req.getSavedObjectsClient().update('url', doc.id, {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { badRequest } from 'boom';
|
||||
|
||||
export default function (kbnServer, server, config) {
|
||||
export function setupVersionCheck(server, config) {
|
||||
const versionHeader = 'kbn-version';
|
||||
const actualVersion = config.get('pkg.version');
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { badRequest } from 'boom';
|
||||
|
||||
export default function (kbnServer, server, config) {
|
||||
export function setupXsrf(server, config) {
|
||||
const disabled = config.get('server.xsrf.disableProtection');
|
||||
const whitelist = config.get('server.xsrf.whitelist');
|
||||
const versionHeader = 'kbn-version';
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Config } from './config';
|
|||
import loggingConfiguration from './logging/configuration';
|
||||
import configSetupMixin from './config/setup';
|
||||
import httpMixin from './http';
|
||||
import loggingMixin from './logging';
|
||||
import { loggingMixin } from './logging';
|
||||
import warningsMixin from './warnings';
|
||||
import statusMixin from './status';
|
||||
import pidMixin from './pid';
|
||||
|
|
|
@ -2,14 +2,15 @@ import { fromNode } from 'bluebird';
|
|||
import evenBetter from 'even-better';
|
||||
import loggingConfiguration from './configuration';
|
||||
|
||||
export default function (kbnServer, server, config) {
|
||||
// prevent relying on kbnServer so this can be used with other hapi servers
|
||||
kbnServer = null;
|
||||
|
||||
return fromNode(function (cb) {
|
||||
export function setupLogging(server, config) {
|
||||
return fromNode((cb) => {
|
||||
server.register({
|
||||
register: evenBetter,
|
||||
options: loggingConfiguration(config)
|
||||
}, cb);
|
||||
});
|
||||
}
|
||||
|
||||
export function loggingMixin(kbnServer, server, config) {
|
||||
return setupLogging(server, config);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,6 @@ import { FieldFormat } from './field_format';
|
|||
export function fieldFormatsMixin(kbnServer, server) {
|
||||
const fieldFormatClasses = [];
|
||||
|
||||
// for use in the context of a request, the default context
|
||||
server.decorate('request', 'getFieldFormatService', async function () {
|
||||
return await server.fieldFormatServiceFactory(this.getUiSettingsService());
|
||||
});
|
||||
|
||||
// for use outside of the request context, for special cases
|
||||
server.decorate('server', 'fieldFormatServiceFactory', async function (uiSettings) {
|
||||
const uiConfigs = await uiSettings.getAll();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue