Skip to content

Commit 3427206

Browse files
authored
feat(api): support proxyfing meta (#2807)
1 parent d740ed8 commit 3427206

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/services/api/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type AxiosOptions = {
1717

1818
export interface BaseAPIParams {
1919
singleClusterMode?: boolean;
20+
proxyMeta?: boolean;
2021
}
2122

2223
export class BaseYdbAPI extends AxiosWrapper {

src/services/api/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ export class YdbEmbeddedAPI {
3434
singleClusterMode,
3535
csrfTokenGetter = () => undefined,
3636
defaults = {},
37+
proxyMeta = false,
3738
}: {
3839
webVersion?: boolean;
3940
withCredentials?: boolean;
4041
singleClusterMode?: boolean;
4142
csrfTokenGetter?: () => string | undefined;
4243
defaults?: AxiosRequestConfig;
44+
proxyMeta?: boolean;
4345
} = {}) {
4446
const axiosParams: AxiosWrapperOptions = {config: {withCredentials, ...defaults}};
45-
const baseApiParams = {singleClusterMode};
47+
const baseApiParams = {singleClusterMode, proxyMeta};
4648

4749
this.auth = new AuthAPI(axiosParams, baseApiParams);
4850
if (webVersion) {

src/services/api/meta.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper';
2+
13
import {metaBackend as META_BACKEND} from '../../store';
24
import type {MetaCapabilitiesResponse} from '../../types/api/capabilities';
35
import type {
@@ -8,11 +10,20 @@ import type {
810
} from '../../types/api/meta';
911
import {parseMetaTenants} from '../parsers/parseMetaTenants';
1012

11-
import type {AxiosOptions} from './base';
13+
import type {AxiosOptions, BaseAPIParams} from './base';
1214
import {BaseYdbAPI} from './base';
1315

1416
export class MetaAPI extends BaseYdbAPI {
15-
getPath(path: string, _clusterName?: string) {
17+
proxyMeta?: boolean;
18+
constructor(axiosOptions?: AxiosWrapperOptions, {proxyMeta}: BaseAPIParams = {}) {
19+
super(axiosOptions);
20+
21+
this.proxyMeta = proxyMeta;
22+
}
23+
getPath(path: string, clusterName?: string) {
24+
if (this.proxyMeta && clusterName) {
25+
return `${META_BACKEND}/proxy/cluster/${clusterName}${path}`;
26+
}
1627
return `${META_BACKEND ?? ''}${path}`;
1728
}
1829

0 commit comments

Comments
 (0)