fix(dashboard): noindex all paths other than root and status

This commit is contained in:
alyssa 2024-12-11 05:46:23 +09:00
parent 008caa8473
commit eb7df8bddb
2 changed files with 10 additions and 2 deletions

View file

@ -2,9 +2,9 @@ name: Build dashboard Docker image
on:
push:
branches: [main]
paths:
- 'dashboard/**'
- '.github/workflows/dashboard.yml'
jobs:
build:

View file

@ -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)