fah/middlewares.go

18 lines
347 B
Go
Raw Normal View History

package main
import (
"fmt"
"net/http"
"strings"
)
func jsonHeaderMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.Path)
if strings.HasPrefix(r.URL.Path, "/api/") {
w.Header().Add("Content-Type", "application/json")
}
next.ServeHTTP(w, r)
})
}