From 04740155b02f68f4891aff0d6ce455d2617ce5ae Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 1 May 2023 11:35:58 -0500 Subject: [PATCH 1/2] chore: 404 Requests to workspace proxy direct back to the primary --- enterprise/wsproxy/wsproxy.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/enterprise/wsproxy/wsproxy.go b/enterprise/wsproxy/wsproxy.go index 3f03d486fe87c..2c45d3516475b 100644 --- a/enterprise/wsproxy/wsproxy.go +++ b/enterprise/wsproxy/wsproxy.go @@ -10,8 +10,6 @@ import ( "strings" "time" - "github.com/coder/coder/coderd/httpapi" - "github.com/go-chi/chi/v5" "github.com/google/uuid" "github.com/prometheus/client_golang/prometheus" @@ -20,12 +18,14 @@ import ( "cdr.dev/slog" "github.com/coder/coder/buildinfo" + "github.com/coder/coder/coderd/httpapi" "github.com/coder/coder/coderd/httpmw" "github.com/coder/coder/coderd/tracing" "github.com/coder/coder/coderd/workspaceapps" "github.com/coder/coder/coderd/wsconncache" "github.com/coder/coder/codersdk" "github.com/coder/coder/enterprise/wsproxy/wsproxysdk" + "github.com/coder/coder/site" ) type Options struct { @@ -233,6 +233,15 @@ func New(ctx context.Context, opts *Options) (*Server, error) { r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) }) // TODO: @emyrk should this be authenticated or debounced? 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: fmt.Sprintf("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."), + RetryEnabled: false, + DashboardURL: opts.DashboardURL.String(), + }) + }) return s, nil } From 00162b049e87f21731672722381d7932528f8a0f Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 1 May 2023 12:55:55 -0500 Subject: [PATCH 2/2] Remove unnecessary sprintf --- enterprise/wsproxy/wsproxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enterprise/wsproxy/wsproxy.go b/enterprise/wsproxy/wsproxy.go index 2c45d3516475b..706ec971d2aa8 100644 --- a/enterprise/wsproxy/wsproxy.go +++ b/enterprise/wsproxy/wsproxy.go @@ -237,7 +237,7 @@ func New(ctx context.Context, opts *Options) (*Server, error) { site.RenderStaticErrorPage(rw, r, site.ErrorPageData{ Status: 404, Title: "Route Not Found", - Description: fmt.Sprintf("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."), + 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.", RetryEnabled: false, DashboardURL: opts.DashboardURL.String(), })