Skip to content

Commit ca55402

Browse files
authored
make defaultRoute accessible in NP Config (#52308)
* defaultRoute was not provided to the NP * improve defaultRoute validation * add test that defaultRoute is read from config * update tests
1 parent 6db76a7 commit ca55402

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

src/core/server/http/http_config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ export const config = {
3838
validate: match(validBasePathRegex, "must start with a slash, don't end with one"),
3939
})
4040
),
41-
defaultRoute: schema.maybe(schema.string()),
41+
defaultRoute: schema.maybe(
42+
schema.string({
43+
validate(value) {
44+
if (!value.startsWith('/')) {
45+
return 'must start with a slash';
46+
}
47+
},
48+
})
49+
),
4250
cors: schema.conditional(
4351
schema.contextRef('dev'),
4452
true,

src/core/server/legacy/config/__snapshots__/legacy_object_to_config_adapter.test.ts.snap

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/server/legacy/config/legacy_object_to_config_adapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
6262
return {
6363
autoListen: configValue.autoListen,
6464
basePath: configValue.basePath,
65+
defaultRoute: configValue.defaultRoute,
6566
cors: configValue.cors,
6667
host: configValue.host,
6768
maxPayload: configValue.maxPayloadBytes,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import * as kbnTestServer from '../../../../test_utils/kbn_server';
20+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
21+
import { Root } from '../../../../core/server/root';
22+
23+
describe('default route provider', () => {
24+
let root: Root;
25+
26+
afterEach(async () => await root.shutdown());
27+
28+
it('redirects to the configured default route', async function() {
29+
root = kbnTestServer.createRoot({
30+
server: {
31+
defaultRoute: '/app/some/default/route',
32+
},
33+
});
34+
35+
await root.setup();
36+
await root.start();
37+
38+
const kbnServer = kbnTestServer.getKbnServer(root);
39+
40+
kbnServer.server.decorate('request', 'getSavedObjectsClient', function() {
41+
return {
42+
get: (type: string, id: string) => ({ attributes: {} }),
43+
};
44+
});
45+
46+
const { status, header } = await kbnTestServer.request.get(root, '/');
47+
48+
expect(status).toEqual(302);
49+
expect(header).toMatchObject({
50+
location: '/app/some/default/route',
51+
});
52+
});
53+
});

src/legacy/server/saved_objects/saved_objects_mixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function getImportableAndExportableTypes({ kbnServer, visibleTypes }) {
5555
);
5656
}
5757

58-
export async function savedObjectsMixin(kbnServer, server) {
58+
export function savedObjectsMixin(kbnServer, server) {
5959
const migrator = kbnServer.newPlatform.__internals.kibanaMigrator;
6060
const mappings = migrator.getActiveMappings();
6161
const allTypes = Object.keys(getRootPropertiesObjects(mappings));

0 commit comments

Comments
 (0)