MCPcopy Index your code
hub / github.com/coder/coder / buildAppLinkURL

Function buildAppLinkURL

cli/open.go:652–688  ·  view source on GitHub ↗

buildAppLinkURL returns the URL to open the app in the browser. It follows similar logic to the TypeScript implementation in site/src/utils/app.ts except that all URLs returned are absolute and based on the provided base URL.

(baseURL *url.URL, workspace codersdk.Workspace, agent codersdk.WorkspaceAgent, app codersdk.WorkspaceApp, appsHost, preferredPathBase string)

Source from the content-addressed store, hash-verified

650// It follows similar logic to the TypeScript implementation in site/src/utils/app.ts
651// except that all URLs returned are absolute and based on the provided base URL.
652func buildAppLinkURL(baseURL *url.URL, workspace codersdk.Workspace, agent codersdk.WorkspaceAgent, app codersdk.WorkspaceApp, appsHost, preferredPathBase string) string {
653 // If app is external, return the URL directly
654 if app.External {
655 return app.URL
656 }
657
658 var u url.URL
659 u.Scheme = baseURL.Scheme
660 u.Host = baseURL.Host
661 // We redirect if we don't include a trailing slash, so we always include one to avoid extra roundtrips.
662 u.Path = fmt.Sprintf(
663 "%s/@%s/%s.%s/apps/%s/",
664 preferredPathBase,
665 workspace.OwnerName,
666 workspace.Name,
667 agent.Name,
668 url.PathEscape(app.Slug),
669 )
670 if app.Command != "" {
671 u.Path = fmt.Sprintf(
672 "%s/@%s/%s.%s/terminal",
673 preferredPathBase,
674 workspace.OwnerName,
675 workspace.Name,
676 agent.Name,
677 )
678 q := u.Query()
679 q.Set("app", app.Slug)
680 u.RawQuery = q.Encode()
681 }
682
683 if appsHost != "" && app.Subdomain && app.SubdomainName != "" {
684 u.Host = strings.Replace(appsHost, "*", app.SubdomainName, 1)
685 u.Path = "/"
686 }
687 return u.String()
688}

Callers 2

openAppMethod · 0.85
Test_buildAppLinkURLFunction · 0.85

Calls 4

EncodeMethod · 0.80
ReplaceMethod · 0.80
SetMethod · 0.65
StringMethod · 0.45

Tested by 1

Test_buildAppLinkURLFunction · 0.68