Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/experiments/client.ts
2500 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import * as configcat from "configcat-js";
8
import { ConfigCatClient } from "@gitpod/gitpod-protocol/lib/experiments/configcat";
9
import { Client } from "@gitpod/gitpod-protocol/lib/experiments/types";
10
import { LogLevel } from "configcat-common";
11
12
let client: Client | undefined;
13
14
export function getExperimentsClient(): Client {
15
// We have already instantiated a client, we can just re-use it.
16
if (client !== undefined) {
17
return client;
18
}
19
20
client = newProxyConfigCatClient();
21
return client;
22
}
23
24
function newProxyConfigCatClient(): Client {
25
const clientKey = "gitpod"; // the client key is populated by the proxy
26
const client = configcat.createClientWithLazyLoad(clientKey, {
27
logger: configcat.createConsoleLogger(LogLevel.Error),
28
cacheTimeToLiveSeconds: 60 * 3, // 3 minutes
29
requestTimeoutMs: 1500,
30
baseUrl: `${window.location.origin}/configcat`,
31
});
32
33
return new ConfigCatClient(client);
34
}
35
36