chore: initial public commit

This commit is contained in:
Gabe Farrell 2025-06-11 19:45:39 -04:00
commit fc9054b78c
250 changed files with 32809 additions and 0 deletions

View file

@ -0,0 +1,24 @@
package middleware
import (
"net/http"
"slices"
"github.com/gabehf/koito/internal/cfg"
"github.com/gabehf/koito/internal/logger"
)
func AllowedHosts(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
l := logger.Get()
if cfg.AllowAllHosts() {
next.ServeHTTP(w, r)
return
} else if slices.Contains(cfg.AllowedHosts(), r.Host) {
next.ServeHTTP(w, r)
return
}
l.Warn().Msgf("Request denied from host %s. If you want to allow requests like this, add the host to your %s variable", r.Host, cfg.ALLOWED_HOSTS_ENV)
w.WriteHeader(http.StatusForbidden)
})
}