From 9775f0385464c0112d89fbd8b9992295fc666adb Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 30 May 2024 10:28:33 -0600 Subject: [PATCH] add robots.txt --- handler.go | 7 +++++++ robots.txt | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 robots.txt diff --git a/handler.go b/handler.go index d7c2804d..7c2943c9 100644 --- a/handler.go +++ b/handler.go @@ -23,6 +23,7 @@ import ( "bytes" "context" "crypto" + _ "embed" "encoding/hex" "encoding/json" "errors" @@ -331,6 +332,9 @@ var HeaderXPoweredBy = fmt.Sprintf("go-openbmclapi/%s; url=https://github.com/Li var accessedTeapotMux sync.RWMutex var accessedTeapot = make(map[string]struct{}) +//go:embed robots.txt +var robotTxtContent string + func (cr *Cluster) ServeHTTP(rw http.ResponseWriter, req *http.Request) { method := req.Method u := req.URL @@ -401,6 +405,9 @@ func (cr *Cluster) ServeHTTP(rw http.ResponseWriter, req *http.Request) { cr.handlerAPIv0.ServeHTTP(rw, req) return } + case rawpath == "/robots.txt": + http.ServeContent(rw, req, "robots.txt", time.Time{}, strings.NewReader(robotTxtContent)) + return case strings.HasPrefix(rawpath, "/dashboard/"): if !config.Dashboard.Enable { http.NotFound(rw, req) diff --git a/robots.txt b/robots.txt new file mode 100644 index 00000000..72569390 --- /dev/null +++ b/robots.txt @@ -0,0 +1,6 @@ + +User-Agent: * + +Disallow: /api/ +Disallow: /dashboard/login +Disallow: /dashboard/settings/