Skip to content

feat: add switch http(s) button to error page #12942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename
  • Loading branch information
f0ssel committed Apr 26, 2024
commit e291e8c724b30edb60c25a5096e0321f7efaf8fe
6 changes: 3 additions & 3 deletions coderd/tailnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,16 @@ func (s *ServerTailnet) ReverseProxy(targetURL, dashboardURL *url.URL, agentID u
Scheme: dashboardURL.Scheme,
}
if app.IsPort() {
if app.Protocol() == "https" {
if app.PortProtocol() == "https" {
app.ChangePortProtocol("http")
} else {
app.ChangePortProtocol("https")
}

switchURL.Host = fmt.Sprintf("%s%s", app.String(), strings.TrimPrefix(wildcardHostname, "*"))
switchLink = switchURL.String()
switchTarget = app.Protocol()
additional += fmt.Sprintf("This error seems to be due to an app protocol mismatch, try switching to %s.", strings.ToUpper(app.Protocol()))
switchTarget = app.PortProtocol()
additional += fmt.Sprintf("This error seems to be due to an app protocol mismatch, try switching to %s.", strings.ToUpper(app.PortProtocol()))
}
}

Expand Down
6 changes: 3 additions & 3 deletions coderd/workspaceapps/appurl/appurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (a ApplicationURL) IsPort() bool {
return true
}

func (a ApplicationURL) Protocol() string {
func (a ApplicationURL) PortProtocol() string {
if strings.HasSuffix(a.AppSlugOrPort, "s") {
trimmed := strings.TrimSuffix(a.AppSlugOrPort, "s")
_, err := strconv.ParseInt(trimmed, 10, 64)
Expand All @@ -121,7 +121,7 @@ func (a ApplicationURL) Protocol() string {

func (a *ApplicationURL) ChangePortProtocol(target string) {
if target == "http" {
if a.Protocol() == "http" {
if a.PortProtocol() == "http" {
return
}
trimmed := strings.TrimSuffix(a.AppSlugOrPort, "s")
Expand All @@ -132,7 +132,7 @@ func (a *ApplicationURL) ChangePortProtocol(target string) {
}

if target == "https" {
if a.Protocol() == "https" {
if a.PortProtocol() == "https" {
return
}
_, err := strconv.ParseInt(a.AppSlugOrPort, 10, 64)
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspaceapps/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func (s *Server) proxyWorkspaceApp(rw http.ResponseWriter, r *http.Request, appT
r.URL.Path = path
appURL.RawQuery = ""
if app.IsPort() {
appURL.Scheme = app.Protocol()
appURL.Scheme = app.PortProtocol()
}

proxy := s.AgentProvider.ReverseProxy(appURL, s.DashboardURL, appToken.AgentID, app, s.Hostname)
Expand Down