robots.go 593 B

12345678910111213141516171819202122232425262728
  1. package controllers
  2. import (
  3. "net/http"
  4. "strings"
  5. "github.com/owncast/owncast/core/data"
  6. )
  7. // GetRobotsDotTxt returns the contents of our robots.txt.
  8. func GetRobotsDotTxt(w http.ResponseWriter, r *http.Request) {
  9. w.Header().Set("Content-Type", "text/plain")
  10. contents := []string{
  11. "User-agent: *",
  12. "Disallow: /admin",
  13. "Disallow: /api",
  14. }
  15. if data.GetDisableSearchIndexing() {
  16. contents = append(contents, "Disallow: /")
  17. }
  18. txt := []byte(strings.Join(contents, "\n"))
  19. if _, err := w.Write(txt); err != nil {
  20. http.Error(w, err.Error(), http.StatusInternalServerError)
  21. }
  22. }