Skip to content

Commit

Permalink
Fix maps plugin async route registration
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Apr 24, 2024
1 parent bdac77d commit 28d0960
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 3 additions & 2 deletions x-pack/plugins/maps/server/data_indexing/indexing_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import { getMatchingIndexes } from './get_indexes_matching_pattern';
export function initIndexingRoutes({
router,
logger,
dataPlugin,
getDataPlugin,
}: {
router: IRouter<DataRequestHandlerContext>;
logger: Logger;
dataPlugin: DataPluginStart;
getDataPlugin: () => Promise<DataPluginStart>;
securityPlugin?: SecurityPluginStart;
}) {
router.versioned
Expand Down Expand Up @@ -58,6 +58,7 @@ export function initIndexingRoutes({
async (context, request, response) => {
const coreContext = await context.core;
const { index, mappings } = request.body;
const dataPlugin = await getDataPlugin();
const indexPatternsService = await dataPlugin.indexPatterns.dataViewsServiceFactory(
coreContext.savedObjects.client,
coreContext.elasticsearch.client.asCurrentUser,
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/maps/server/mvt/mvt_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const CACHE_TIMEOUT_SECONDS = 60 * 60;
export function initMVTRoutes({
router,
logger,
core,
getCore,
}: {
router: IRouter<DataRequestHandlerContext>;
logger: Logger;
core: CoreStart;
getCore: () => Promise<CoreStart>;
}) {
router.versioned
.get({
Expand Down Expand Up @@ -93,7 +93,7 @@ export function initMVTRoutes({
abortController: makeAbortController(request),
body: tileRequest.body,
context,
core,
core: await getCore(),
executionContext: makeExecutionContext({
type: 'server',
name: APP_ID,
Expand Down Expand Up @@ -173,7 +173,7 @@ export function initMVTRoutes({
abortController: makeAbortController(request),
body: tileRequest.body,
context,
core,
core: await getCore(),
executionContext: makeExecutionContext({
type: 'server',
name: APP_ID,
Expand Down
24 changes: 18 additions & 6 deletions x-pack/plugins/maps/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
import { schema } from '@kbn/config-schema';
import fs from 'fs';
import path from 'path';
import { CoreSetup, CoreStart, IRouter, Logger } from '@kbn/core/server';
import { CoreSetup, IRouter, Logger } from '@kbn/core/server';
import { DataRequestHandlerContext } from '@kbn/data-plugin/server';
import { INDEX_SETTINGS_API_PATH, FONTS_API_PATH } from '../common/constants';
import { getIndexPatternSettings } from './lib/get_index_pattern_settings';
import { initMVTRoutes } from './mvt/mvt_routes';
import { initIndexingRoutes } from './data_indexing/indexing_routes';
import { StartDeps } from './types';

export async function initRoutes(coreSetup: CoreSetup, logger: Logger): Promise<void> {
export function initRoutes(coreSetup: CoreSetup<StartDeps>, logger: Logger) {
const router: IRouter<DataRequestHandlerContext> = coreSetup.http.createRouter();
const [coreStart, { data: dataPlugin }]: [CoreStart, StartDeps] =
(await coreSetup.getStartServices()) as unknown as [CoreStart, StartDeps];

router.versioned
.get({
Expand Down Expand Up @@ -109,6 +107,20 @@ export async function initRoutes(coreSetup: CoreSetup, logger: Logger): Promise<
}
);

initMVTRoutes({ router, logger, core: coreStart });
initIndexingRoutes({ router, logger, dataPlugin });
initMVTRoutes({
router,
logger,
getCore: async () => {
const [core] = await coreSetup.getStartServices();
return core;
},
});
initIndexingRoutes({
router,
logger,
getDataPlugin: async () => {
const [, { data }] = await coreSetup.getStartServices();
return data;
},
});
}

0 comments on commit 28d0960

Please sign in to comment.