diff --git a/hub/server.go b/hub/server.go index 7d7a35d6..009b122d 100644 --- a/hub/server.go +++ b/hub/server.go @@ -44,8 +44,8 @@ func newHub(signal chan struct{}) { r.Use(cors.Handler) - r.Get("/traffic", traffic) - r.Get("/logs", getLogs) + r.With(jsonContentType).Get("/traffic", traffic) + r.With(jsonContentType).Get("/logs", getLogs) r.Mount("/configs", configRouter()) r.Mount("/proxies", proxyRouter()) r.Mount("/rules", ruleRouter()) @@ -56,6 +56,14 @@ func newHub(signal chan struct{}) { } } +func jsonContentType(next http.Handler) http.Handler { + fn := func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + next.ServeHTTP(w, r) + } + return http.HandlerFunc(fn) +} + func traffic(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK)