Skip to content

Commit 5a6f83f

Browse files
committed
Expose serverBasePath on client-side (#58070)
1 parent e6a3f98 commit 5a6f83f

File tree

19 files changed

+86
-16
lines changed

19 files changed

+86
-16
lines changed

docs/development/core/public/kibana-plugin-public.ibasepath.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export interface IBasePath
1919
| [get](./kibana-plugin-public.ibasepath.get.md) | <code>() =&gt; string</code> | Gets the <code>basePath</code> string. |
2020
| [prepend](./kibana-plugin-public.ibasepath.prepend.md) | <code>(url: string) =&gt; string</code> | Prepends <code>path</code> with the basePath. |
2121
| [remove](./kibana-plugin-public.ibasepath.remove.md) | <code>(url: string) =&gt; string</code> | Removes the prepended basePath from the <code>path</code>. |
22+
| [serverBasePath](./kibana-plugin-public.ibasepath.serverbasepath.md) | <code>string</code> | Returns the server's root basePath as configured, without any namespace prefix.<!-- -->See for getting the basePath value for a specific request |
2223

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [IBasePath](./kibana-plugin-public.ibasepath.md) &gt; [serverBasePath](./kibana-plugin-public.ibasepath.serverbasepath.md)
4+
5+
## IBasePath.serverBasePath property
6+
7+
Returns the server's root basePath as configured, without any namespace prefix.
8+
9+
See for getting the basePath value for a specific request
10+
11+
<b>Signature:</b>
12+
13+
```typescript
14+
readonly serverBasePath: string;
15+
```

src/core/public/http/base_path.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,14 @@ describe('BasePath', () => {
8888
});
8989
});
9090
});
91+
92+
describe('serverBasePath', () => {
93+
it('defaults to basePath', () => {
94+
expect(new BasePath('/foo/bar').serverBasePath).toEqual('/foo/bar');
95+
});
96+
97+
it('returns value when passed into constructor', () => {
98+
expect(new BasePath('/foo/bar', '/foo').serverBasePath).toEqual('/foo');
99+
});
100+
});
91101
});

src/core/public/http/base_path.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
import { modifyUrl } from '../../utils';
3939

4040
export class BasePath {
41-
constructor(private readonly basePath: string = '') {}
41+
constructor(
42+
private readonly basePath: string = '',
43+
public readonly serverBasePath: string = basePath
44+
) {}
4245

4346
public get = () => {
4447
return this.basePath;

src/core/public/http/http_service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export class HttpService implements CoreService<HttpSetup, HttpStart> {
3939

4040
public setup({ injectedMetadata, fatalErrors }: HttpDeps): HttpSetup {
4141
const kibanaVersion = injectedMetadata.getKibanaVersion();
42-
const basePath = new BasePath(injectedMetadata.getBasePath());
42+
const basePath = new BasePath(
43+
injectedMetadata.getBasePath(),
44+
injectedMetadata.getServerBasePath()
45+
);
4346
const fetchService = new Fetch({ basePath, kibanaVersion });
4447
const loadingCount = this.loadingCount.setup({ fatalErrors });
4548

src/core/public/http/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ export interface IBasePath {
9494
* Removes the prepended basePath from the `path`.
9595
*/
9696
remove: (url: string) => string;
97+
98+
/**
99+
* Returns the server's root basePath as configured, without any namespace prefix.
100+
*
101+
* See {@link BasePath.get} for getting the basePath value for a specific request
102+
*/
103+
readonly serverBasePath: string;
97104
}
98105

99106
/**

src/core/public/injected_metadata/injected_metadata_service.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { InjectedMetadataService, InjectedMetadataSetup } from './injected_metad
2121
const createSetupContractMock = () => {
2222
const setupContract: jest.Mocked<InjectedMetadataSetup> = {
2323
getBasePath: jest.fn(),
24+
getServerBasePath: jest.fn(),
2425
getKibanaVersion: jest.fn(),
2526
getKibanaBranch: jest.fn(),
2627
getCspConfig: jest.fn(),

src/core/public/injected_metadata/injected_metadata_service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface InjectedMetadataParams {
5454
buildNumber: number;
5555
branch: string;
5656
basePath: string;
57+
serverBasePath: string;
5758
category?: AppCategory;
5859
csp: {
5960
warnLegacyBrowsers: boolean;
@@ -115,6 +116,10 @@ export class InjectedMetadataService {
115116
return this.state.basePath;
116117
},
117118

119+
getServerBasePath: () => {
120+
return this.state.serverBasePath;
121+
},
122+
118123
getKibanaVersion: () => {
119124
return this.state.version;
120125
},
@@ -161,6 +166,7 @@ export class InjectedMetadataService {
161166
*/
162167
export interface InjectedMetadataSetup {
163168
getBasePath: () => string;
169+
getServerBasePath: () => string;
164170
getKibanaBuildNumber: () => number;
165171
getKibanaBranch: () => string;
166172
getKibanaVersion: () => string;

src/core/public/public.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ export interface IBasePath {
718718
get: () => string;
719719
prepend: (url: string) => string;
720720
remove: (url: string) => string;
721+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "BasePath"
722+
readonly serverBasePath: string;
721723
}
722724

723725
// @public

src/core/server/rendering/__snapshots__/rendering_service.test.ts.snap

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

0 commit comments

Comments
 (0)