From eb7df8bddb8468374b462ed2a0fdef54928379b5 Mon Sep 17 00:00:00 2001 From: alyssa Date: Wed, 11 Dec 2024 05:46:23 +0900 Subject: [PATCH] fix(dashboard): noindex all paths other than root and status --- .github/workflows/dashboard.yml | 2 +- dashboard/main.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 72f1cf47..ae1b36e1 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -2,9 +2,9 @@ name: Build dashboard Docker image on: push: - branches: [main] paths: - 'dashboard/**' + - '.github/workflows/dashboard.yml' jobs: build: diff --git a/dashboard/main.go b/dashboard/main.go index 926b23fc..e657c740 100644 --- a/dashboard/main.go +++ b/dashboard/main.go @@ -38,15 +38,23 @@ func main() { r.Use(func(next http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + // only index root and status pages + if r.URL.Path != "/" && r.URL.Path != "/status" { + rw.Header().Set("X-Robots-Tag", "noindex") + } + rw.Header().Set("X-PluralKit-Version", version) next.ServeHTTP(rw, r) }) }) + r.Get("/robots.txt", func(rw http.ResponseWriter, r *http.Request) { + rw.Write([]byte("User-Agent: *\nAllow: /$\nAllow: /status\nDisallow: /\n")) + }) + r.NotFound(notFoundHandler) r.Get("/profile/{type}/{id}", func(rw http.ResponseWriter, r *http.Request) { - rw.Header().Set("X-Robots-Tag", "noindex") defer func() { if a := recover(); a != nil { notFoundHandler(rw, r)