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.
()
| 48 | // returned if a subdomain app hostname is not provided but the app is a |
| 49 | // subdomain app. |
| 50 | func (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 | |
| 83 | type Request struct { |
| 84 | AccessMethod AccessMethod `json:"access_method"` |