Skip to content

Commit 0ab922a

Browse files
committed
reverse parse order
1 parent 3fe6787 commit 0ab922a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

coderd/workspaceapps/request.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,17 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
290290
agentNameOrID = r.AgentNameOrID
291291
appURL string
292292
appSharingLevel database.AppSharingLevel
293-
portUint, portUintErr = strconv.ParseUint(r.AppSlugOrPort, 10, 16)
294-
protocol = "http"
293+
potentialPortStr = strings.TrimSuffix(r.AppSlugOrPort, "s")
294+
portUint, portUintErr = strconv.ParseUint(potentialPortStr, 10, 16)
295295
)
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 {
296+
if portUintErr == nil {
297+
// If we fail to parse the port, see if it's a port with a trailing "s" for
298+
// HTTPS.
299+
protocol := "http"
300+
if strings.HasSuffix(r.AppSlugOrPort, "s") {
302301
protocol = "https"
303302
}
304-
}
305303

306-
if portUintErr == nil {
307304
if r.AccessMethod != AccessMethodSubdomain {
308305
// TODO(@deansheather): this should return a 400 instead of a 500.
309306
return nil, xerrors.New("port-based URLs are only supported for subdomain-based applications")

0 commit comments

Comments
 (0)