Skip to content

Commit 87ae0be

Browse files
committed
feat: add s suffix to use HTTPS for ports
1 parent 65f8d18 commit 87ae0be

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

coderd/workspaceapps/request.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,18 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
291291
appURL string
292292
appSharingLevel database.AppSharingLevel
293293
portUint, portUintErr = strconv.ParseUint(r.AppSlugOrPort, 10, 16)
294+
protocol = "http"
294295
)
296+
// If we fail to parse the port, see if it's a port with a trailing "s" for
297+
// HTTPS.
298+
if portUintErr != nil && strings.HasSuffix(r.AppSlugOrPort, "s") {
299+
appSlugOrPort := strings.TrimRight(r.AppSlugOrPort, "s")
300+
portUint, portUintErr = strconv.ParseUint(appSlugOrPort, 10, 16)
301+
if portUintErr == nil {
302+
protocol = "https"
303+
}
304+
}
305+
295306
if portUintErr == nil {
296307
if r.AccessMethod != AccessMethodSubdomain {
297308
// TODO(@deansheather): this should return a 400 instead of a 500.
@@ -312,7 +323,7 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
312323
// "anonymous app". We only support HTTP for port-based URLs.
313324
//
314325
// This is only supported for subdomain-based applications.
315-
appURL = fmt.Sprintf("http://127.0.0.1:%d", portUint)
326+
appURL = fmt.Sprintf("%s://127.0.0.1:%d", protocol, portUint)
316327
appSharingLevel = database.AppSharingLevelOwner
317328

318329
// Port sharing authorization

0 commit comments

Comments
 (0)