Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/supervisor/frontend/src/ide/gitpod-server-compatibility.ts
2501 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 { serverUrl } from "../shared/urls";
8
9
const currentHost = new URL(serverUrl.toString()).hostname;
10
11
export const isSaaS = currentHost === "gitpod.io";
12
13
const versionRegex = new RegExp("main.(\\d+)");
14
15
function getVersionInfo(version: string) {
16
const result = versionRegex.exec(version);
17
if (!result) {
18
return;
19
}
20
return Number(result[1]);
21
}
22
23
const serverVersion = (async () => {
24
const url = serverUrl.withApi({ pathname: "/version" }).toString();
25
const fetchVersion = async (retry: number) => {
26
try {
27
const resp = await fetch(url);
28
const currentVersionStr = await resp.text();
29
return getVersionInfo(currentVersionStr);
30
} catch (e) {
31
if (retry - 1 <= 0) {
32
throw e;
33
}
34
fetchVersion(retry - 1);
35
}
36
};
37
try {
38
return await fetchVersion(3);
39
} catch (e) {
40
console.error("failed to fetch server verson:", e);
41
}
42
})();
43
44
export async function isSaaSServerGreaterThan(version: string) {
45
if (!isSaaS) {
46
return false;
47
}
48
const serverVersionNum = await serverVersion;
49
const versionNum = getVersionInfo(version);
50
return !!serverVersionNum && !!versionNum && serverVersionNum >= versionNum;
51
}
52
53