Skip to content
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
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/integrations_manager/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { Request, Server, ServerRoute } from 'hapi';
export { Request, ServerRoute } from 'hapi';

// the contract with the registry
export type IntegrationList = IntegrationListItem[];
Expand Down
13 changes: 7 additions & 6 deletions x-pack/legacy/plugins/integrations_manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import { i18n } from '@kbn/i18n';
import { resolve } from 'path';
import { LegacyPluginInitializer, LegacyPluginOptions } from 'src/legacy/types';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { Feature } from '../xpack_main/server/lib/feature_registry';
import { PLUGIN_ID } from './common/constants';
import { Server } from './common/types';
import manifest from './kibana.json';
import { CoreSetup, Plugin as ServerPlugin, PluginInitializerContext } from './server/plugin';
import { mappings, savedObjectSchemas } from './server/saved_objects';
Expand Down Expand Up @@ -75,12 +75,13 @@ const pluginOptions: LegacyPluginOptions = {
init(server: Server) {
server.plugins.xpack_main.registerFeature(feature);

const coreSetup: CoreSetup = {
http: {
route: server.route.bind(server),
},
};
// convert hapi instance to KbnServer
// `kbnServer.server` is the same hapi instance
// `kbnServer.newPlatform` has important values
const kbnServer = (server as unknown) as KbnServer;
const initializerContext: PluginInitializerContext = {};
const coreSetup: CoreSetup = kbnServer.newPlatform.setup.core;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 now you're using the actual new platform instead of approximating it with a shim.


new ServerPlugin(initializerContext).setup(coreSetup);
},
postInit: undefined,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/integrations_manager/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'ui/autoload/all';
import 'ui/autoload/styles';
import chrome from 'ui/chrome';
import { npSetup, npStart } from 'ui/new_platform';
import { Plugin, PluginInitializerContext, PluginStart } from './plugin';
import { PLUGIN_ID } from '../common/constants';
import { Plugin, PluginInitializerContext, PluginStart } from './plugin';

const REACT_APP_ROOT_ID = `react-${PLUGIN_ID}-root`;
const template = `<div id="${REACT_APP_ROOT_ID}" class="integrationsManagerReactRoot"></div>`;
Expand Down
14 changes: 4 additions & 10 deletions x-pack/legacy/plugins/integrations_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ServerRoute } from '../common/types';
import { HttpServiceSetup, CoreStart } from 'src/core/server';
import { fetchList } from './registry';
import { routes } from './routes';

export interface CoreSetup {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also pull in CoreSetup from src/core/server

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that at one point but got this error
Screen Shot 2019-06-28 at 9 28 00 AM

I can avoid it using InternalCoreSetup but that didn’t seem better.
Screen Shot 2019-06-28 at 9 28 58 AM

I took a pass at importing from KbnServer or src/legacy but didn’t get anywhere. Happy to learn about other options.

http: HttpServiceSetup;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CoreStart {}

export interface HttpServiceSetup {
route(route: ServerRoute | ServerRoute[]): void;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PluginInitializerContext {}

Expand All @@ -28,11 +21,12 @@ export type PluginStart = ReturnType<Plugin['start']>;
export class Plugin {
constructor(initializerContext: PluginInitializerContext) {}
public setup(core: CoreSetup) {
const { route } = core.http;
const { server } = core.http;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http.server is there for backwards compatibility/legacy, but you can also switch to http.registerRouter to only rely on new platform functionality.

@mshustov mshustov Jun 28, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a reminder that route handler interfaces is not stabilized yet. it will be exposed once we implement #39767

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skaapgif lol, you’re calling out all my side quests from #39833. There was a version of it with that. I didn’t use it because it felt too early (@restrry’s point about the rfc, issues w/import, etc). Happy to try it out anytime.


// map routes to handlers
routes.forEach(route);
routes.forEach(route => server.route(route));

// the JS API for other consumers
return {
getList: fetchList,
};
Expand Down