Skip to content

Commit acaa254

Browse files
authored
feat: link with protocol on shared ports (coder#12908)
1 parent 2f2a395 commit acaa254

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

coderd/workspaceapps/apptest/apptest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
11651165
appDetails := setupProxyTest(t, &DeploymentOptions{
11661166
ServeHTTPS: true,
11671167
})
1168+
// using the fact that Apps.Port and Apps.PortHTTPS are the same port here
11681169
port, err := strconv.ParseInt(appDetails.Apps.Port.AppSlugOrPort, 10, 32)
11691170
require.NoError(t, err)
11701171
_, err = appDetails.SDKClient.UpsertWorkspaceAgentPortShare(ctx, appDetails.Workspace.ID, codersdk.UpsertWorkspaceAgentPortShareRequest{
@@ -1178,7 +1179,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
11781179
publicAppClient := appDetails.AppClient(t)
11791180
publicAppClient.SetSessionToken("")
11801181

1181-
resp, err := requestWithRetries(ctx, t, publicAppClient, http.MethodGet, appDetails.SubdomainAppURL(appDetails.Apps.Port).String(), nil)
1182+
resp, err := requestWithRetries(ctx, t, publicAppClient, http.MethodGet, appDetails.SubdomainAppURL(appDetails.Apps.PortHTTPS).String(), nil)
11821183
require.NoError(t, err)
11831184
defer resp.Body.Close()
11841185
require.Equal(t, http.StatusOK, resp.StatusCode)

coderd/workspaceapps/apptest/setup.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type Details struct {
116116
Authenticated App
117117
Public App
118118
Port App
119+
PortHTTPS App
119120
}
120121
}
121122

@@ -247,6 +248,12 @@ func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *De
247248
AgentName: agnt.Name,
248249
AppSlugOrPort: strconv.Itoa(int(opts.port)),
249250
}
251+
details.Apps.PortHTTPS = App{
252+
Username: me.Username,
253+
WorkspaceName: workspace.Name,
254+
AgentName: agnt.Name,
255+
AppSlugOrPort: strconv.Itoa(int(opts.port)) + "s",
256+
}
250257

251258
return details
252259
}

coderd/workspaceapps/appurl/appurl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ func (a ApplicationURL) Path() string {
9090
//
9191
// Subdomains should be in the form:
9292
//
93-
// ({PREFIX}---)?{PORT/APP_SLUG}--{AGENT_NAME}--{WORKSPACE_NAME}--{USERNAME}
93+
// ({PREFIX}---)?{PORT{s?}/APP_SLUG}--{AGENT_NAME}--{WORKSPACE_NAME}--{USERNAME}
9494
// e.g.
9595
// https://8080--main--dev--dean.hi.c8s.io
96+
// https://8080s--main--dev--dean.hi.c8s.io
9697
// https://app--main--dev--dean.hi.c8s.io
9798
// https://prefix---8080--main--dev--dean.hi.c8s.io
9899
// https://prefix---app--main--dev--dean.hi.c8s.io

coderd/workspaceapps/request.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
350350
}
351351
// No port share found, so we keep default to owner.
352352
} else {
353-
if ps.Protocol == database.PortShareProtocolHttps {
354-
// Apply HTTPS protocol if specified.
355-
appURL = fmt.Sprintf("https://127.0.0.1:%d", portUint)
356-
}
357353
appSharingLevel = ps.ShareLevel
358354
}
359355
} else {

site/src/modules/resources/PortForwardButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
393393
agent.name,
394394
workspaceName,
395395
username,
396+
share.protocol === "https",
396397
);
397398
const label = share.port;
398399
return (

site/src/utils/portForward.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export const portForwardURL = (
44
agentName: string,
55
workspaceName: string,
66
username: string,
7+
https = false,
78
): string => {
89
const { location } = window;
10+
const suffix = https ? "s" : "";
911

10-
const subdomain = `${
11-
isNaN(port) ? 3000 : port
12-
}--${agentName}--${workspaceName}--${username}`;
12+
const subdomain = `${port}${suffix}--${agentName}--${workspaceName}--${username}`;
1313
return `${location.protocol}//${host}`.replace("*", subdomain);
1414
};
1515

0 commit comments

Comments
 (0)