owncast/webserver/handlers/robots.go
Gabe Kangas 0b5d7c8a4d
Config repository (#3988)
* WIP

* fix(test): fix ap test failing

* fix: fix unkeyed fields being used

* chore(tests): clean up browser tests by splitting out federation UI tests
2024-11-15 19:20:58 -08:00

29 lines
665 B
Go

package handlers
import (
"net/http"
"strings"
"github.com/owncast/owncast/persistence/configrepository"
)
// GetRobotsDotTxt returns the contents of our robots.txt.
func GetRobotsDotTxt(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
contents := []string{
"User-agent: *",
"Disallow: /admin",
"Disallow: /api",
}
configRepository := configrepository.Get()
if configRepository.GetDisableSearchIndexing() {
contents = append(contents, "Disallow: /")
}
txt := []byte(strings.Join(contents, "\n"))
if _, err := w.Write(txt); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}