Skip to content

Commit

Permalink
Make sure routes are properly registered
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Apr 6, 2021
1 parent 17a48e3 commit 0f9b61e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ export function createServerRouteRepository<
TRouteHandlerResources extends ServerRouteHandlerResources = never,
TRouteCreateOptions extends ServerRouteCreateOptions = never
>(): ServerRouteRepository<TRouteHandlerResources, TRouteCreateOptions, {}> {
const routes: Record<string, any> = {};
let routes: Record<string, any> = {};

return {
add(route) {
routes[route.endpoint] = route;
routes = {
...routes,
[route.endpoint]: route,
};

return this as any;
},
merge(repository) {
Object.assign(routes, repository.getRoutes());
routes = {
...routes,
...Object.fromEntries(repository.getRoutes().map((route) => [route.endpoint, route])),
};

return this as any;
},
getRoutes: () => Object.values(routes),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/public/services/rest/createCallApmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import { CoreSetup, CoreStart } from 'kibana/public';
import {
import type {
ClientRequestParamsOf,
EndpointOf,
formatRequest,
ReturnOf,
RouteRepositoryClient,
} from '@kbn/server-route-repository';
import { formatRequest } from '@kbn/server-route-repository/target/format_request';
import { FetchOptions } from '../../../common/fetch_options';
import { callApi } from './callApi';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/apm/server/routes/register_routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export function registerRoutes({

const { method, pathname } = parseEndpoint(endpoint);

console.log({
method,
pathname,
});

(router[method] as RouteRegistrar<
typeof method,
ApmPluginRequestHandlerContext
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ const serviceDependenciesRoute = createApmServerRoute({
}),
query: t.intersection([
t.type({
numBuckets: t.number,
numBuckets: toNumberRt,
}),
environmentRt,
rangeRt,
Expand Down

0 comments on commit 0f9b61e

Please sign in to comment.