Skip to content

Commit

Permalink
Pass envoyPrefix query param to CoreClient constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
vbabich committed Apr 11, 2023
1 parent 85ce600 commit ff72711
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/code-studio/src/main/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
createCoreClient,
createSessionWrapper,
getAuthType,
getEnvoyPrefix,
getLoginOptions,
getSessionDetails,
} from './SessionUtils';
Expand Down Expand Up @@ -170,7 +171,12 @@ function AppInit(props: AppInitProps) {
navigator.userAgent
);

const coreClient = createCoreClient();
const envoyPrefix = getEnvoyPrefix();
const options =
envoyPrefix != null
? { headers: { 'envoy-prefix': envoyPrefix } }
: undefined;
const coreClient = createCoreClient(options);
const authType = getAuthType();
log.info(`Login using auth type ${authType}...`);
const [loginOptions, sessionDetails] = await Promise.all([
Expand Down
10 changes: 8 additions & 2 deletions packages/code-studio/src/main/SessionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SessionWrapper,
} from '@deephaven/dashboard-core-plugins';
import dh, {
ConnectOptions,
CoreClient,
IdeConnection,
LoginOptions,
Expand Down Expand Up @@ -42,6 +43,11 @@ export function getAuthType(): AUTH_TYPE {
}
}

export function getEnvoyPrefix(): string | null {
const searchParams = new URLSearchParams(window.location.search);
return searchParams.get('envoyPrefix');
}

/**
* @returns New connection to the server
*/
Expand Down Expand Up @@ -89,12 +95,12 @@ export async function createSessionWrapper(
};
}

export function createCoreClient(): CoreClient {
export function createCoreClient(options?: ConnectOptions): CoreClient {
const websocketUrl = getWebsocketUrl();

log.info('createCoreClient', websocketUrl);

return new dh.CoreClient(websocketUrl);
return new dh.CoreClient(websocketUrl, options);
}

async function requestParentLoginOptions(): Promise<LoginOptions> {
Expand Down
6 changes: 5 additions & 1 deletion packages/jsapi-types/src/dh.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,14 +1066,18 @@ export interface StorageService {
createDirectory(path: string): Promise<void>;
}

export interface ConnectOptions {
headers?: Record<string, string>;
}

export interface CoreClientContructor extends Evented {
EVENT_CONNECT: string;
EVENT_DISCONNECT: string;
EVENT_RECONNECT: string;
EVENT_RECONNECT_AUTH_FAILED: string;
EVENT_REFRESH_TOKEN_UPDATED: string;
LOGIN_TYPE_ANONYMOUS: string;
new (serverUrl: string): CoreClient;
new (serverUrl: string, options?: ConnectOptions): CoreClient;
}

export interface CoreClient extends CoreClientContructor {
Expand Down

0 comments on commit ff72711

Please sign in to comment.