reprogl
30 строк · 686.0 Байт
1package middlewares2
3import (4"net/http"5"strings"6
7"xelbot.com/reprogl/container"8)
9
10func CDN(next http.Handler) http.Handler {11return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {12if container.IsCDN(r) {13if r.URL.Path == "" || r.URL.Path == "/" {14w.Header().Set("Content-Type", "text/plain")15w.Write([]byte("This is static assets storage"))16
17return18} else if r.URL.Path != "/robots.txt" &&19r.URL.Path != "/sitemap.xml" &&20r.URL.Path != "/headers" &&21!strings.HasPrefix(r.URL.Path, "/images/avatar/") {22http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)23
24return25}26}27
28next.ServeHTTP(w, r)29})30}
31