Skip to content

Commit 8b08a16

Browse files
committed
clean up
1 parent bbbd3c2 commit 8b08a16

File tree

3 files changed

+18
-53
lines changed

3 files changed

+18
-53
lines changed

coderd/tailnet.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ func (s *ServerTailnet) ReverseProxy(targetURL, dashboardURL *url.URL, agentID u
357357
proxy := httputil.NewSingleHostReverseProxy(&tgt)
358358
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, theErr error) {
359359
var (
360-
desc = "Failed to proxy request to application: " + theErr.Error()
361-
additional = ""
362-
switchLink = ""
363-
switchTarget = ""
360+
desc = "Failed to proxy request to application: " + theErr.Error()
361+
additionalInfo = ""
362+
additionalButtonLink = ""
363+
additionalButtonText = ""
364364
)
365365

366366
var tlsError tls.RecordHeaderError
@@ -373,17 +373,16 @@ func (s *ServerTailnet) ReverseProxy(targetURL, dashboardURL *url.URL, agentID u
373373
}
374374
_, protocol, isPort := app.PortInfo()
375375
if isPort {
376+
targetProtocol := "https"
376377
if protocol == "https" {
377-
app = app.ChangePortProtocol("http")
378-
}
379-
if protocol == "http" {
380-
app = app.ChangePortProtocol("https")
378+
targetProtocol = "http"
381379
}
380+
app = app.ChangePortProtocol(targetProtocol)
382381

383382
switchURL.Host = fmt.Sprintf("%s%s", app.String(), strings.TrimPrefix(wildcardHostname, "*"))
384-
switchLink = switchURL.String()
385-
switchTarget = protocol
386-
additional += fmt.Sprintf("This error seems to be due to an app protocol mismatch, try switching to %s.", strings.ToUpper(protocol))
383+
additionalButtonLink = switchURL.String()
384+
additionalButtonText = fmt.Sprintf("Switch to %s", strings.ToUpper(targetProtocol))
385+
additionalInfo += fmt.Sprintf("This error seems to be due to an app protocol mismatch, try switching to %s.", strings.ToUpper(targetProtocol))
387386
}
388387
}
389388

@@ -393,9 +392,9 @@ func (s *ServerTailnet) ReverseProxy(targetURL, dashboardURL *url.URL, agentID u
393392
Description: desc,
394393
RetryEnabled: true,
395394
DashboardURL: dashboardURL.String(),
396-
AdditionalInfo: additional,
397-
AdditionalButtonLink: switchLink,
398-
AdditionalButtonText: fmt.Sprintf("Switch to %s", strings.ToUpper(switchTarget)),
395+
AdditionalInfo: additionalInfo,
396+
AdditionalButtonLink: additionalButtonLink,
397+
AdditionalButtonText: additionalButtonText,
399398
})
400399
}
401400
proxy.Director = s.director(agentID, proxy.Director)

coderd/workspaceapps/appurl/appurl.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,7 @@ func (a ApplicationURL) Path() string {
8484
return fmt.Sprintf("/@%s/%s.%s/apps/%s", a.Username, a.WorkspaceName, a.AgentName, a.AppSlugOrPort)
8585
}
8686

87-
// func (a ApplicationURL) IsPort() bool {
88-
// // check if https port
89-
// if strings.HasSuffix(a.AppSlugOrPort, "s") {
90-
// trimmed := strings.TrimSuffix(a.AppSlugOrPort, "s")
91-
// _, err := strconv.ParseInt(trimmed, 10, 64)
92-
// //nolint:gosimple
93-
// if err != nil {
94-
// return false
95-
// }
96-
97-
// return true
98-
// }
99-
100-
// // check if port at all
101-
// _, err := strconv.ParseInt(a.AppSlugOrPort, 10, 64)
102-
// //nolint:gosimple
103-
// if err != nil {
104-
// return false
105-
// }
106-
107-
// return true
108-
// }
109-
110-
// func (a ApplicationURL) PortProtocol() string {
111-
// if strings.HasSuffix(a.AppSlugOrPort, "s") {
112-
// trimmed := strings.TrimSuffix(a.AppSlugOrPort, "s")
113-
// _, err := strconv.ParseInt(trimmed, 10, 64)
114-
// if err == nil {
115-
// return "https"
116-
// }
117-
// }
118-
119-
// return "http"
120-
// }
121-
87+
// PortInfo returns the port, protocol, and whether the AppSlugOrPort is a port or not.
12288
func (a ApplicationURL) PortInfo() (uint, string, bool) {
12389
var (
12490
port uint64

site/static/error.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
.container {
3434
--side-padding: 24px;
3535
width: 100%;
36-
max-width: calc(460px + var(--side-padding) * 2);
36+
max-width: calc(500px + var(--side-padding) * 2);
3737
padding: 0 var(--side-padding);
3838
text-align: center;
3939
}
@@ -198,9 +198,9 @@ <h3>Warnings</h3>
198198
</div>
199199
{{ end }}
200200
<div class="button-group">
201-
{{- if and .Error.AdditionalButtonText .Error.AdditionButtonLink }}
202-
<a href="{{ .Error.AdditionButtonLink }}"
203-
>Switch to {{ .Error.AdditionalButtonText }}</a
201+
{{- if and .Error.AdditionalButtonText .Error.AdditionalButtonLink }}
202+
<a href="{{ .Error.AdditionalButtonLink }}"
203+
>{{ .Error.AdditionalButtonText }}</a
204204
>
205205
{{ end }} {{- if .Error.RetryEnabled }}
206206
<button onclick="window.location.reload()">Retry</button>

0 commit comments

Comments
 (0)