Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pass optional envoyPrefix query param to CoreClient constructor #1219

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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