Skip to content

Commit

Permalink
Expose serverBasePath on client-side
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Feb 19, 2020
1 parent 29ac6fe commit a007b19
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface IBasePath
| [get](./kibana-plugin-public.ibasepath.get.md) | <code>() =&gt; string</code> | Gets the <code>basePath</code> string. |
| [prepend](./kibana-plugin-public.ibasepath.prepend.md) | <code>(url: string) =&gt; string</code> | Prepends <code>path</code> with the basePath. |
| [remove](./kibana-plugin-public.ibasepath.remove.md) | <code>(url: string) =&gt; string</code> | Removes the prepended basePath from the <code>path</code>. |
| [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 |

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[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)

## IBasePath.serverBasePath property

Returns the server's root basePath as configured, without any namespace prefix.

See for getting the basePath value for a specific request

<b>Signature:</b>

```typescript
readonly serverBasePath: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [IHttpFetchError](./kibana-plugin-public.ihttpfetcherror.md) &gt; [name](./kibana-plugin-public.ihttpfetcherror.name.md)

## IHttpFetchError.name property

<b>Signature:</b>

```typescript
readonly name: string;
```
10 changes: 10 additions & 0 deletions src/core/public/http/base_path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ describe('BasePath', () => {
});
});
});

describe('serverBasePath', () => {
it('defaults to basePath', () => {
expect(new BasePath('/foo/bar').serverBasePath).toEqual('/foo/bar');
});

it('returns value when passed into constructor', () => {
expect(new BasePath('/foo/bar', '/foo').serverBasePath).toEqual('/foo');
});
});
});
5 changes: 4 additions & 1 deletion src/core/public/http/base_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
import { modifyUrl } from '../../utils';

export class BasePath {
constructor(private readonly basePath: string = '') {}
constructor(
private readonly basePath: string = '',
public readonly serverBasePath: string = basePath
) {}

public get = () => {
return this.basePath;
Expand Down
5 changes: 4 additions & 1 deletion src/core/public/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class HttpService implements CoreService<HttpSetup, HttpStart> {

public setup({ injectedMetadata, fatalErrors }: HttpDeps): HttpSetup {
const kibanaVersion = injectedMetadata.getKibanaVersion();
const basePath = new BasePath(injectedMetadata.getBasePath());
const basePath = new BasePath(
injectedMetadata.getBasePath(),
injectedMetadata.getServerBasePath()
);
const fetchService = new Fetch({ basePath, kibanaVersion });
const loadingCount = this.loadingCount.setup({ fatalErrors });

Expand Down
7 changes: 7 additions & 0 deletions src/core/public/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ export interface IBasePath {
* Removes the prepended basePath from the `path`.
*/
remove: (url: string) => string;

/**
* Returns the server's root basePath as configured, without any namespace prefix.
*
* See {@link BasePath.get} for getting the basePath value for a specific request
*/
readonly serverBasePath: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { InjectedMetadataService, InjectedMetadataSetup } from './injected_metad
const createSetupContractMock = () => {
const setupContract: jest.Mocked<InjectedMetadataSetup> = {
getBasePath: jest.fn(),
getServerBasePath: jest.fn(),
getKibanaVersion: jest.fn(),
getKibanaBranch: jest.fn(),
getCspConfig: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface InjectedMetadataParams {
buildNumber: number;
branch: string;
basePath: string;
serverBasePath: string;
category?: AppCategory;
csp: {
warnLegacyBrowsers: boolean;
Expand Down Expand Up @@ -115,6 +116,10 @@ export class InjectedMetadataService {
return this.state.basePath;
},

getServerBasePath: () => {
return this.state.serverBasePath;
},

getKibanaVersion: () => {
return this.state.version;
},
Expand Down Expand Up @@ -161,6 +166,7 @@ export class InjectedMetadataService {
*/
export interface InjectedMetadataSetup {
getBasePath: () => string;
getServerBasePath: () => string;
getKibanaBuildNumber: () => number;
getKibanaBranch: () => string;
getKibanaVersion: () => string;
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ export interface IBasePath {
get: () => string;
prepend: (url: string) => string;
remove: (url: string) => string;
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "BasePath"
readonly serverBasePath: string;
}

// @public
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/core/server/rendering/rendering_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class RenderingService implements CoreService<RenderingServiceSetup> {
) => {
const { env } = this.coreContext;
const basePath = http.basePath.get(request);
const serverBasePath = http.basePath.serverBasePath;
const settings = {
defaults: uiSettings.getRegistered(),
user: includeUserSettings ? await uiSettings.getUserProvided() : {},
Expand All @@ -79,6 +80,7 @@ export class RenderingService implements CoreService<RenderingServiceSetup> {
buildNumber: env.packageInfo.buildNum,
branch: env.packageInfo.branch,
basePath,
serverBasePath,
env,
legacyMode: appId !== 'core',
i18n: {
Expand Down
1 change: 1 addition & 0 deletions src/core/server/rendering/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface RenderingMetadata {
buildNumber: number;
branch: string;
basePath: string;
serverBasePath: string;
env: Env;
legacyMode: boolean;
i18n: {
Expand Down

0 comments on commit a007b19

Please sign in to comment.