Skip to content

Commit ae26a60

Browse files
Use the Gitpod endpoint from the preferences everywhere (#72)
1 parent c984c5c commit ae26a60

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

src/api/Gitpod/Models/IOrganizations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import fetch from "node-fetch";
22

3+
import { getPublicAPIEndpoint } from "../../../preferences/gitpod_endpoint";
4+
35
import { IOrganizationError } from "./IOrganizationError";
46
import { GitpodDataModel } from "./Model";
57

8+
const publicAPIEndpoint = getPublicAPIEndpoint();
69
const organizationURLs = {
7-
getOrganizations: "https://api.gitpod.io/gitpod.experimental.v1.TeamsService/ListTeams",
10+
getOrganizations: `${publicAPIEndpoint}/gitpod.experimental.v1.TeamsService/ListTeams`,
811
};
912

1013
export class IOrganization implements GitpodDataModel {

src/api/Gitpod/Models/IWorkspace.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fetch from "node-fetch";
22

3+
import { getPublicAPIEndpoint, getGitpodEndpoint } from "../../../preferences/gitpod_endpoint";
34
import { CreateWorkspace, WorkspaceStreamer } from "../WorkspaceStreamer";
45

56
import { IWorkspaceError } from "./IWorkspaceError";
@@ -21,12 +22,13 @@ type ICreateWorkspaceParams = {
2122
};
2223
};
2324

25+
const publicAPIEndpoint = getPublicAPIEndpoint();
2426
const workspaceURLs = {
25-
getWorkspace: "https://api.gitpod.io/gitpod.experimental.v1.WorkspacesService/GetWorkspace",
26-
getAllWorkspaces: "https://api.gitpod.io/gitpod.experimental.v1.WorkspacesService/ListWorkspaces",
27-
deleteWorkspace: "https://api.gitpod.io/gitpod.experimental.v1.WorkspacesService/DeleteWorkspace",
28-
startWorkspace: "https://api.gitpod.io/gitpod.experimental.v1.WorkspacesService/StartWorkspace",
29-
stopWorkspace: "https://api.gitpod.io/gitpod.experimental.v1.WorkspacesService/StopWorkspace",
27+
getWorkspace: `${publicAPIEndpoint}/gitpod.experimental.v1.WorkspacesService/GetWorkspace`,
28+
getAllWorkspaces: `${publicAPIEndpoint}/gitpod.experimental.v1.WorkspacesService/ListWorkspaces`,
29+
deleteWorkspace: `${publicAPIEndpoint}/gitpod.experimental.v1.WorkspacesService/DeleteWorkspace`,
30+
startWorkspace: `${publicAPIEndpoint}/gitpod.experimental.v1.WorkspacesService/StartWorkspace`,
31+
stopWorkspace: `${publicAPIEndpoint}/gitpod.experimental.v1.WorkspacesService/StopWorkspace`,
3032
};
3133

3234
export class IWorkspace implements GitpodDataModel {
@@ -159,7 +161,7 @@ export class IWorkspace implements GitpodDataModel {
159161
this.instanceId = workspace.status.instance.instanceId;
160162
this.initialized = true;
161163
this.createdAt = workspace.status.instance.createdAt;
162-
this.ideURL = workspace.status.instance ? workspace.status.instance.status.url : "https://gitpod.io";
164+
this.ideURL = workspace.status.instance ? workspace.status.instance.status.url : getGitpodEndpoint();
163165
this.repository = workspace.context.git.repository.name;
164166

165167
if (workspace.status.instance.status.gitStatus) {

src/api/Gitpod/WorkspaceStreamer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { EventEmitter } from "events";
22

33
import WebSocket from "ws";
44

5+
import { getGitpodEndpoint, getWebsocketEndpoint } from "../../preferences/gitpod_endpoint";
6+
57
import { NewIWorkspaceErrorObject } from "./Models/IWorkspaceError";
68
import { NewIWorkspaceUpdateObject } from "./Models/IWorkspaceUpdate";
79

@@ -44,12 +46,15 @@ export class WorkspaceStreamer extends EventEmitter {
4446

4547
constructor(token: string) {
4648
super();
49+
50+
const gitpodEndpoint = getGitpodEndpoint();
51+
const gitpodWebsocketEndpoint = getWebsocketEndpoint();
4752
try {
4853
WorkspaceStreamer.token = token;
4954
// Create new transport for GRPC Messages
50-
WorkspaceStreamer.webSocket = new WebSocket("wss://gitpod.io/api/v1", {
55+
WorkspaceStreamer.webSocket = new WebSocket(`${gitpodWebsocketEndpoint}/api/v1`, {
5156
headers: {
52-
Origin: new URL("https://gitpod.io").origin,
57+
Origin: new URL(gitpodEndpoint).origin,
5358
Authorization: `Bearer ${token}`,
5459
},
5560
});

src/helpers/getVSCodeEncodedURI.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { IWorkspace } from "../api/Gitpod/Models/IWorkspace";
2+
import { getGitpodEndpoint } from "../preferences/gitpod_endpoint";
23

34
export function getCodeEncodedURI(workspace: IWorkspace): string {
5+
const gitpodEndpoint = getGitpodEndpoint();
46
const data = {
57
instanceId: workspace.instanceId,
68
workspaceId: workspace.getWorkspaceId(),
7-
gitpodHost: "https://gitpod.io",
9+
gitpodHost: gitpodEndpoint,
810
};
911

1012
const vsCodeURI =

src/menubar_workspaces.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import { getFocusedBrowserContext } from "./helpers/getFocusedContext";
2222
import { getCodeEncodedURI } from "./helpers/getVSCodeEncodedURI";
2323
import { splitUrl } from "./helpers/splitURL";
2424
import { dashboardPreferences } from "./preferences/dashboard_preferences";
25+
import { getGitpodEndpoint } from "./preferences/gitpod_endpoint";
2526
import { Preferences } from "./preferences/repository_preferences";
2627

2728
export default function command() {
2829
const preferences = getPreferenceValues<dashboardPreferences>();
2930
const EditorPreferences = getPreferenceValues<Preferences>();
31+
const gitpodEndpoint = getGitpodEndpoint();
3032
const [isUnauthorised, setIsUnauthorized] = useState<boolean>(false);
3133

3234
const workspaceManager = new WorkspaceManager(preferences.access_token ?? "");
@@ -199,19 +201,19 @@ export default function command() {
199201
title="Dashboard"
200202
icon={GitpodIcons.dashboard_icon}
201203
shortcut={{ modifiers: ["cmd", "shift"], key: "d" }}
202-
onAction={() => open("https://gitpod.io/workspaces")}
204+
onAction={() => open(`${gitpodEndpoint}/workspaces`)}
203205
/>
204206
<MenuBarExtra.Item
205207
title="My Projects"
206208
shortcut={{ modifiers: ["cmd", "shift"], key: "p" }}
207209
icon={GitpodIcons.project_icon}
208-
onAction={() => open("https://gitpod.io/projects")}
210+
onAction={() => open(`${gitpodEndpoint}/projects`)}
209211
/>
210212
<MenuBarExtra.Item
211213
title="My Settings"
212214
shortcut={{ modifiers: ["cmd", "shift"], key: "s" }}
213215
icon={GitpodIcons.settings_icon}
214-
onAction={() => open("https://gitpod.io/user/account")}
216+
onAction={() => open(`${gitpodEndpoint}/user/account`)}
215217
/>
216218
<MenuBarExtra.Item
217219
title="Documentation"

src/preferences/gitpod_endpoint.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ export function getGitpodEndpoint(): string {
44
const { gitpodUrl } = getPreferenceValues();
55
return gitpodUrl;
66
}
7+
8+
export function getPublicAPIEndpoint(): string {
9+
const { gitpodUrl } = getPreferenceValues();
10+
return gitpodUrl.replace("https://", "https://api.");
11+
}
12+
13+
export function getWebsocketEndpoint(): string {
14+
const { gitpodUrl } = getPreferenceValues();
15+
return gitpodUrl.replace("https://", "wss://");
16+
}

0 commit comments

Comments
 (0)