refactor: build application URL (#9601)

* refactor: build application URL

* fix
This commit is contained in:
Marcin Tojek
2023-09-08 14:01:57 +00:00
committed by GitHub
parent 392b11272b
commit ad23075e1b
6 changed files with 53 additions and 25 deletions
+9 -2
View File
@@ -13,6 +13,7 @@ import (
"github.com/google/uuid"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/codersdk"
)
@@ -61,8 +62,14 @@ func (r IssueTokenRequest) AppBaseURL() (*url.URL, error) {
if r.AppHostname == "" {
return nil, xerrors.New("subdomain app hostname is required to generate subdomain app URL")
}
appHost := fmt.Sprintf("%s--%s--%s--%s", r.AppRequest.AppSlugOrPort, r.AppRequest.AgentNameOrID, r.AppRequest.WorkspaceNameOrID, r.AppRequest.UsernameOrID)
u.Host = strings.Replace(r.AppHostname, "*", appHost, 1)
appHost := httpapi.ApplicationURL{
AppSlugOrPort: r.AppRequest.AppSlugOrPort,
AgentName: r.AppRequest.AgentNameOrID,
WorkspaceName: r.AppRequest.WorkspaceNameOrID,
Username: r.AppRequest.UsernameOrID,
}
u.Host = strings.Replace(r.AppHostname, "*", appHost.String(), 1)
u.Path = r.AppRequest.BasePath
return u, nil
default: