Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07608fc

Browse files
Emyrkkylecarbs
andauthored
chore: fix proxy 404 page (#7421)
* chore: fix proxy 404 page---------Co-authored-by: Kyle Carberry <kyle@coder.com>
1 parent2624ee8 commit07608fc

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

‎enterprise/wsproxy/wsproxy.go

Lines changed: 5 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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
typeErrorPageDatastruct {
609-
Statusint
609+
Statusint
610+
// HideStatus will remove the status code from the page.
611+
HideStatusbool
610612
Titlestring
611613
Descriptionstring
612614
RetryEnabledbool

‎site/site_test.go

Lines changed: 31 additions & 0 deletions
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+
funcTestRenderStaticErrorPageNoStatus(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+
deferresp.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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<metacharset="UTF-8"/>
88
<metahttp-equiv="X-UA-Compatible"content="IE=edge"/>
99
<metaname="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
<divclass="button-group">
129135
{{- if .Error.RetryEnabled }}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp