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

Method AppBaseURL

coderd/workspaceapps/request.go:50–81  ·  view source on GitHub ↗

AppBaseURL returns the base URL of this specific app request. An error is returned if a subdomain app hostname is not provided but the app is a subdomain app.

()

Source from the content-addressed store, hash-verified

48// returned if a subdomain app hostname is not provided but the app is a
49// subdomain app.
50func (r IssueTokenRequest) AppBaseURL() (*url.URL, error) {
51 u, err := url.Parse(r.PathAppBaseURL)
52 if err != nil {
53 return nil, xerrors.Errorf("parse path app base URL: %w", err)
54 }
55
56 switch r.AppRequest.AccessMethod {
57 case AccessMethodPath, AccessMethodTerminal:
58 u.Path = r.AppRequest.BasePath
59 if !strings.HasSuffix(u.Path, "/") {
60 u.Path += "/"
61 }
62 return u, nil
63 case AccessMethodSubdomain:
64 if r.AppHostname == "" {
65 return nil, xerrors.New("subdomain app hostname is required to generate subdomain app URL")
66 }
67
68 appHost := appurl.ApplicationURL{
69 Prefix: r.AppRequest.Prefix,
70 AppSlugOrPort: r.AppRequest.AppSlugOrPort,
71 AgentName: r.AppRequest.AgentNameOrID,
72 WorkspaceName: r.AppRequest.WorkspaceNameOrID,
73 Username: r.AppRequest.UsernameOrID,
74 }
75 u.Host = strings.Replace(r.AppHostname, "*", appHost.String(), 1)
76 u.Path = r.AppRequest.BasePath
77 return u, nil
78 default:
79 return nil, xerrors.Errorf("invalid access method: %q", r.AppRequest.AccessMethod)
80 }
81}
82
83type Request struct {
84 AccessMethod AccessMethod `json:"access_method"`

Callers 1

IssueMethod · 0.80

Calls 5

StringMethod · 0.95
ReplaceMethod · 0.80
ParseMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected