Path: blob/main/components/dashboard/src/experiments/client.ts
2500 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import * as configcat from "configcat-js";7import { ConfigCatClient } from "@gitpod/gitpod-protocol/lib/experiments/configcat";8import { Client } from "@gitpod/gitpod-protocol/lib/experiments/types";9import { LogLevel } from "configcat-common";1011let client: Client | undefined;1213export function getExperimentsClient(): Client {14// We have already instantiated a client, we can just re-use it.15if (client !== undefined) {16return client;17}1819client = newProxyConfigCatClient();20return client;21}2223function newProxyConfigCatClient(): Client {24const clientKey = "gitpod"; // the client key is populated by the proxy25const client = configcat.createClientWithLazyLoad(clientKey, {26logger: configcat.createConsoleLogger(LogLevel.Error),27cacheTimeToLiveSeconds: 60 * 3, // 3 minutes28requestTimeoutMs: 1500,29baseUrl: `${window.location.origin}/configcat`,30});3132return new ConfigCatClient(client);33}343536