feat: add robots.txt

This commit is contained in:
eyjhb
2025-06-06 11:16:27 +02:00
committed by nblock
parent a058bf3cd3
commit d77874373d
3 changed files with 18 additions and 0 deletions

View File

@@ -67,6 +67,8 @@ systemctl start headscale
[#2625](https://github.com/juanfont/headscale/pull/2625) [#2625](https://github.com/juanfont/headscale/pull/2625)
- Don't crash if config file is missing - Don't crash if config file is missing
[#2656](https://github.com/juanfont/headscale/pull/2656) [#2656](https://github.com/juanfont/headscale/pull/2656)
- Adds `/robots.txt` endpoint to avoid crawlers
[#2643](https://github.com/juanfont/headscale/pull/2643)
## 0.26.1 (2025-06-06) ## 0.26.1 (2025-06-06)

View File

@@ -449,6 +449,7 @@ func (h *Headscale) createRouter(grpcMux *grpcRuntime.ServeMux) *mux.Router {
router.HandleFunc(ts2021UpgradePath, h.NoiseUpgradeHandler). router.HandleFunc(ts2021UpgradePath, h.NoiseUpgradeHandler).
Methods(http.MethodPost, http.MethodGet) Methods(http.MethodPost, http.MethodGet)
router.HandleFunc("/robots.txt", h.RobotsHandler).Methods(http.MethodGet)
router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet) router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet)
router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet) router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet)
router.HandleFunc("/register/{registration_id}", h.authProvider.RegisterHandler). router.HandleFunc("/register/{registration_id}", h.authProvider.RegisterHandler).

View File

@@ -180,6 +180,21 @@ func (h *Headscale) HealthHandler(
respond(nil) respond(nil)
} }
func (h *Headscale) RobotsHandler(
writer http.ResponseWriter,
req *http.Request,
) {
writer.Header().Set("Content-Type", "text/plain")
writer.WriteHeader(http.StatusOK)
_, err := writer.Write([]byte("User-agent: *\nDisallow: /"))
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to write response")
}
}
var codeStyleRegisterWebAPI = styles.Props{ var codeStyleRegisterWebAPI = styles.Props{
styles.Display: "block", styles.Display: "block",
styles.Padding: "20px", styles.Padding: "20px",