Skip to content

Commit 8b1e58c

Browse files
authored
feat: Pass optional envoyPrefix query param to CoreClient constructor (#1219)
1 parent 85ce600 commit 8b1e58c

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

packages/code-studio/src/main/AppInit.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
createCoreClient,
5353
createSessionWrapper,
5454
getAuthType,
55+
getEnvoyPrefix,
5556
getLoginOptions,
5657
getSessionDetails,
5758
} from './SessionUtils';
@@ -170,7 +171,12 @@ function AppInit(props: AppInitProps) {
170171
navigator.userAgent
171172
);
172173

173-
const coreClient = createCoreClient();
174+
const envoyPrefix = getEnvoyPrefix();
175+
const options =
176+
envoyPrefix != null
177+
? { headers: { 'envoy-prefix': envoyPrefix } }
178+
: undefined;
179+
const coreClient = createCoreClient(options);
174180
const authType = getAuthType();
175181
log.info(`Login using auth type ${authType}...`);
176182
const [loginOptions, sessionDetails] = await Promise.all([

packages/code-studio/src/main/SessionUtils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
SessionWrapper,
44
} from '@deephaven/dashboard-core-plugins';
55
import dh, {
6+
ConnectOptions,
67
CoreClient,
78
IdeConnection,
89
LoginOptions,
@@ -42,6 +43,11 @@ export function getAuthType(): AUTH_TYPE {
4243
}
4344
}
4445

46+
export function getEnvoyPrefix(): string | null {
47+
const searchParams = new URLSearchParams(window.location.search);
48+
return searchParams.get('envoyPrefix');
49+
}
50+
4551
/**
4652
* @returns New connection to the server
4753
*/
@@ -89,12 +95,12 @@ export async function createSessionWrapper(
8995
};
9096
}
9197

92-
export function createCoreClient(): CoreClient {
98+
export function createCoreClient(options?: ConnectOptions): CoreClient {
9399
const websocketUrl = getWebsocketUrl();
94100

95101
log.info('createCoreClient', websocketUrl);
96102

97-
return new dh.CoreClient(websocketUrl);
103+
return new dh.CoreClient(websocketUrl, options);
98104
}
99105

100106
async function requestParentLoginOptions(): Promise<LoginOptions> {

packages/jsapi-types/src/dh.types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,14 +1066,18 @@ export interface StorageService {
10661066
createDirectory(path: string): Promise<void>;
10671067
}
10681068

1069+
export interface ConnectOptions {
1070+
headers?: Record<string, string>;
1071+
}
1072+
10691073
export interface CoreClientContructor extends Evented {
10701074
EVENT_CONNECT: string;
10711075
EVENT_DISCONNECT: string;
10721076
EVENT_RECONNECT: string;
10731077
EVENT_RECONNECT_AUTH_FAILED: string;
10741078
EVENT_REFRESH_TOKEN_UPDATED: string;
10751079
LOGIN_TYPE_ANONYMOUS: string;
1076-
new (serverUrl: string): CoreClient;
1080+
new (serverUrl: string, options?: ConnectOptions): CoreClient;
10771081
}
10781082

10791083
export interface CoreClient extends CoreClientContructor {

0 commit comments

Comments
 (0)