From ff8775c225b22c83f4d946b7833225f57c6962a2 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 7 Sep 2022 14:17:08 -0400 Subject: [PATCH] notfound_ui (#57) --- endpoints/frontend/http.go | 4 + endpoints/frontend/notfound_ui/embed.go | 6 + endpoints/frontend/notfound_ui/handler.go | 21 ++ endpoints/frontend/notfound_ui/index.html | 400 ++++++++++++++++++++++ 4 files changed, 431 insertions(+) create mode 100644 endpoints/frontend/notfound_ui/embed.go create mode 100644 endpoints/frontend/notfound_ui/handler.go create mode 100644 endpoints/frontend/notfound_ui/index.html diff --git a/endpoints/frontend/http.go b/endpoints/frontend/http.go index 2f1a767f..1c6d9972 100644 --- a/endpoints/frontend/http.go +++ b/endpoints/frontend/http.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/openziti-test-kitchen/zrok/endpoints/frontend/health_ui" + "github.com/openziti-test-kitchen/zrok/endpoints/frontend/notfound_ui" "github.com/openziti-test-kitchen/zrok/model" "github.com/openziti-test-kitchen/zrok/util" "github.com/openziti-test-kitchen/zrok/zrokdir" @@ -214,12 +215,15 @@ func authHandler(handler http.Handler, realm string, cfg *Config, ctx ziti.Conte } } else { logrus.Infof("%v -> no auth scheme for '%v'", r.RemoteAddr, svcName) + notfound_ui.WriteNotFound(w) } } else { logrus.Infof("%v -> no proxy config for '%v'", r.RemoteAddr, svcName) + notfound_ui.WriteNotFound(w) } } else { logrus.Infof("%v -> service '%v' not found", r.RemoteAddr, svcName) + notfound_ui.WriteNotFound(w) } } else { logrus.Warnf("host '%v' did not match host match, returning health check", r.Host) diff --git a/endpoints/frontend/notfound_ui/embed.go b/endpoints/frontend/notfound_ui/embed.go new file mode 100644 index 00000000..46fb311e --- /dev/null +++ b/endpoints/frontend/notfound_ui/embed.go @@ -0,0 +1,6 @@ +package notfound_ui + +import "embed" + +//go:embed index.html +var FS embed.FS diff --git a/endpoints/frontend/notfound_ui/handler.go b/endpoints/frontend/notfound_ui/handler.go new file mode 100644 index 00000000..11e835f4 --- /dev/null +++ b/endpoints/frontend/notfound_ui/handler.go @@ -0,0 +1,21 @@ +package notfound_ui + +import ( + "github.com/sirupsen/logrus" + "net/http" +) + +func WriteNotFound(w http.ResponseWriter) { + if data, err := FS.ReadFile("index.html"); err == nil { + w.WriteHeader(http.StatusNotFound) + n, err := w.Write(data) + if n != len(data) { + logrus.Errorf("short write") + return + } + if err != nil { + logrus.Error(err) + return + } + } +} diff --git a/endpoints/frontend/notfound_ui/index.html b/endpoints/frontend/notfound_ui/index.html new file mode 100644 index 00000000..b13dceab --- /dev/null +++ b/endpoints/frontend/notfound_ui/index.html @@ -0,0 +1,400 @@ + + + + + + + + + + + zrok + + + +
+ +
+
+

not found!

+
+
+
+ +