Skip to content

Commit 07608fc

Browse files
Emyrkkylecarbs
andauthored
chore: fix proxy 404 page (#7421)
* chore: fix proxy 404 page --------- Co-authored-by: Kyle Carberry <kyle@coder.com>
1 parent 2624ee8 commit 07608fc

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

enterprise/wsproxy/wsproxy.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
235235
r.Get("/healthz-report", s.healthReport)
236236
r.NotFound(func(rw http.ResponseWriter, r *http.Request) {
237237
site.RenderStaticErrorPage(rw, r, site.ErrorPageData{
238-
Status: 404,
239-
Title: "Route Not Found",
240-
Description: "The route you requested does not exist on this workspace proxy. Maybe you intended to make this request to the primary dashboard? Click below to be redirected to the primary site.",
238+
Title: "Head to the Dashboard",
239+
Status: http.StatusBadRequest,
240+
HideStatus: true,
241+
Description: "Workspace Proxies route traffic in terminals and apps directly to your workspace. " +
242+
"This page must be loaded from the dashboard. Click to be redirected!",
241243
RetryEnabled: false,
242244
DashboardURL: opts.DashboardURL.String(),
243245
})

site/site.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ func extractBin(dest string, r io.Reader) (numExtracted int, err error) {
606606
// ErrorPageData contains the variables that are found in
607607
// site/static/error.html.
608608
type ErrorPageData struct {
609-
Status int
609+
Status int
610+
// HideStatus will remove the status code from the page.
611+
HideStatus bool
610612
Title string
611613
Description string
612614
RetryEnabled bool

site/site_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,34 @@ func TestRenderStaticErrorPage(t *testing.T) {
517517
require.Contains(t, bodyStr, "Retry")
518518
require.Contains(t, bodyStr, d.DashboardURL)
519519
}
520+
521+
func TestRenderStaticErrorPageNoStatus(t *testing.T) {
522+
t.Parallel()
523+
524+
d := site.ErrorPageData{
525+
HideStatus: true,
526+
Status: http.StatusBadGateway,
527+
Title: "Bad Gateway 1234",
528+
Description: "shout out colin",
529+
RetryEnabled: true,
530+
DashboardURL: "https://example.com",
531+
}
532+
533+
rw := httptest.NewRecorder()
534+
r := httptest.NewRequest("GET", "/", nil)
535+
site.RenderStaticErrorPage(rw, r, d)
536+
537+
resp := rw.Result()
538+
defer resp.Body.Close()
539+
require.Equal(t, d.Status, resp.StatusCode)
540+
require.Contains(t, resp.Header.Get("Content-Type"), "text/html")
541+
542+
body, err := io.ReadAll(resp.Body)
543+
require.NoError(t, err)
544+
bodyStr := string(body)
545+
require.NotContains(t, bodyStr, strconv.Itoa(d.Status))
546+
require.Contains(t, bodyStr, d.Title)
547+
require.Contains(t, bodyStr, d.Description)
548+
require.Contains(t, bodyStr, "Retry")
549+
require.Contains(t, bodyStr, d.DashboardURL)
550+
}

site/static/error.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<meta charset="UTF-8" />
88
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
99
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10-
<title>{{ .Error.Status }} - {{ .Error.Title }}</title>
10+
<title>
11+
{{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{
12+
.Error.Title }}
13+
</title>
1114
<style>
1215
* {
1316
padding: 0;
@@ -123,7 +126,10 @@
123126
</defs>
124127
</svg>
125128

126-
<h1>{{ .Error.Status }} - {{ .Error.Title }}</h1>
129+
<h1>
130+
{{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{
131+
.Error.Title }}
132+
</h1>
127133
<p>{{ .Error.Description }}</p>
128134
<div class="button-group">
129135
{{- if .Error.RetryEnabled }}

0 commit comments

Comments
 (0)