mirror of https://github.com/coder/coder.git
chore: fix proxy 404 page (#7421)
* chore: fix proxy 404 page --------- Co-authored-by: Kyle Carberry <kyle@coder.com>
This commit is contained in:
parent
2624ee8f12
commit
07608fc3fb
|
@ -235,9 +235,11 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
|
|||
r.Get("/healthz-report", s.healthReport)
|
||||
r.NotFound(func(rw http.ResponseWriter, r *http.Request) {
|
||||
site.RenderStaticErrorPage(rw, r, site.ErrorPageData{
|
||||
Status: 404,
|
||||
Title: "Route Not Found",
|
||||
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.",
|
||||
Title: "Head to the Dashboard",
|
||||
Status: http.StatusBadRequest,
|
||||
HideStatus: true,
|
||||
Description: "Workspace Proxies route traffic in terminals and apps directly to your workspace. " +
|
||||
"This page must be loaded from the dashboard. Click to be redirected!",
|
||||
RetryEnabled: false,
|
||||
DashboardURL: opts.DashboardURL.String(),
|
||||
})
|
||||
|
|
|
@ -606,7 +606,9 @@ func extractBin(dest string, r io.Reader) (numExtracted int, err error) {
|
|||
// ErrorPageData contains the variables that are found in
|
||||
// site/static/error.html.
|
||||
type ErrorPageData struct {
|
||||
Status int
|
||||
Status int
|
||||
// HideStatus will remove the status code from the page.
|
||||
HideStatus bool
|
||||
Title string
|
||||
Description string
|
||||
RetryEnabled bool
|
||||
|
|
|
@ -517,3 +517,34 @@ func TestRenderStaticErrorPage(t *testing.T) {
|
|||
require.Contains(t, bodyStr, "Retry")
|
||||
require.Contains(t, bodyStr, d.DashboardURL)
|
||||
}
|
||||
|
||||
func TestRenderStaticErrorPageNoStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
d := site.ErrorPageData{
|
||||
HideStatus: true,
|
||||
Status: http.StatusBadGateway,
|
||||
Title: "Bad Gateway 1234",
|
||||
Description: "shout out colin",
|
||||
RetryEnabled: true,
|
||||
DashboardURL: "https://example.com",
|
||||
}
|
||||
|
||||
rw := httptest.NewRecorder()
|
||||
r := httptest.NewRequest("GET", "/", nil)
|
||||
site.RenderStaticErrorPage(rw, r, d)
|
||||
|
||||
resp := rw.Result()
|
||||
defer resp.Body.Close()
|
||||
require.Equal(t, d.Status, resp.StatusCode)
|
||||
require.Contains(t, resp.Header.Get("Content-Type"), "text/html")
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
bodyStr := string(body)
|
||||
require.NotContains(t, bodyStr, strconv.Itoa(d.Status))
|
||||
require.Contains(t, bodyStr, d.Title)
|
||||
require.Contains(t, bodyStr, d.Description)
|
||||
require.Contains(t, bodyStr, "Retry")
|
||||
require.Contains(t, bodyStr, d.DashboardURL)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ running). */}}
|
|||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{ .Error.Status }} - {{ .Error.Title }}</title>
|
||||
<title>
|
||||
{{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{
|
||||
.Error.Title }}
|
||||
</title>
|
||||
<style>
|
||||
* {
|
||||
padding: 0;
|
||||
|
@ -123,7 +126,10 @@ running). */}}
|
|||
</defs>
|
||||
</svg>
|
||||
|
||||
<h1>{{ .Error.Status }} - {{ .Error.Title }}</h1>
|
||||
<h1>
|
||||
{{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{
|
||||
.Error.Title }}
|
||||
</h1>
|
||||
<p>{{ .Error.Description }}</p>
|
||||
<div class="button-group">
|
||||
{{- if .Error.RetryEnabled }}
|
||||
|
|
Loading…
Reference in New Issue