-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a stub endpoint plugin #50082
Add a stub endpoint plugin #50082
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "endpoint", | ||
"version": "1.0.0", | ||
"kibanaVersion": "kibana", | ||
"configPath": ["x-pack", "endpoint"], | ||
"server": true, | ||
"ui": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { AppMountContext, AppMountParameters } from 'kibana/public'; | ||
|
||
/** | ||
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. | ||
*/ | ||
export function renderApp(appMountContext: AppMountContext, { element }: AppMountParameters) { | ||
appMountContext.core.http.get('/endpoint/hello-world'); | ||
|
||
ReactDOM.render(<AppRoot />, element); | ||
|
||
return function() { | ||
ReactDOM.unmountComponentAtNode(element); | ||
}; | ||
} | ||
|
||
const AppRoot = React.memo(function Root() { | ||
return <h1>Welcome to Endpoint</h1>; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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 { PluginInitializer } from 'kibana/public'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { EndpointPlugin } from './plugin'; | ||
|
||
export const config = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. config schema defined only on the server. lets remove it |
||
schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), | ||
}; | ||
|
||
export const plugin: PluginInitializer<{}, {}> = () => new EndpointPlugin(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 { Plugin, CoreSetup } from 'kibana/public'; | ||
|
||
export class EndpointPlugin implements Plugin<{}, {}> { | ||
public setup(core: CoreSetup) { | ||
core.application.register({ | ||
id: 'endpoint', | ||
title: 'Endpoint', | ||
async mount(context, params) { | ||
const { renderApp } = await import('./applications/endpoint'); | ||
return renderApp(context, params); | ||
}, | ||
}); | ||
return {}; | ||
} | ||
|
||
public start() { | ||
return {}; | ||
} | ||
|
||
public stop() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
import { EndpointPlugin } from './plugin'; | ||
|
||
export const config = { | ||
schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), | ||
}; | ||
|
||
export function plugin() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFYI PluginInitializerContext also passed to the plugin factory export const plugin = (initializerContext: PluginInitializerContext) => new EndpointPlugin(initializerContext) |
||
return new EndpointPlugin(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 { Plugin, CoreSetup } from 'kibana/server'; | ||
import { addRoutes } from './routes'; | ||
|
||
export class EndpointPlugin implements Plugin { | ||
public setup(core: CoreSetup) { | ||
const router = core.http.createRouter(); | ||
addRoutes(router); | ||
} | ||
|
||
public start() {} | ||
public stop() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 { IRouter, KibanaResponseFactory } from 'kibana/server'; | ||
|
||
export function addRoutes(router: IRouter) { | ||
router.get( | ||
{ | ||
path: '/endpoint/hello-world', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFYI: by convention API endpoints are prefixed with |
||
validate: false, | ||
}, | ||
greetingIndex | ||
); | ||
} | ||
|
||
async function greetingIndex(...passedArgs: [unknown, unknown, KibanaResponseFactory]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use import { RequestHandler } from 'src/core/server';
export const greetingIndex: RequestHandler<any, any, any> = async (context, request, response) => { |
||
const [, , response] = passedArgs; | ||
return response.ok({ | ||
body: JSON.stringify({ hello: 'world' }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: don't think |
||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.