Skip to content

Commit

Permalink
Set content type of JSON responses
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Apr 20, 2024
1 parent 777517d commit 6816df3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
httpError(w, r, fmt.Errorf("failed to encode response json: %s", err), http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
case "/account/register":
err := r.ParseForm()
if err != nil {
Expand Down Expand Up @@ -100,6 +102,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
httpError(w, r, fmt.Errorf("failed to encode response json: %s", err), http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
case "/account/logout":
token, err := base64.StdEncoding.DecodeString(r.Header.Get("Authorization"))
if err != nil {
Expand Down Expand Up @@ -127,6 +131,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
httpError(w, r, fmt.Errorf("failed to encode response json: %s", err), http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
case "/game/classicsessioncount":
w.Write([]byte(strconv.Itoa(classicSessionCount)))

Expand Down Expand Up @@ -214,6 +220,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

w.Header().Set("Content-Type", "application/json")

// /daily
case "/daily/seed":
w.Write([]byte(daily.Seed()))
Expand Down Expand Up @@ -249,6 +257,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
httpError(w, r, fmt.Errorf("failed to encode response json: %s", err), http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
case "/daily/rankingpagecount":
var category int
if r.URL.Query().Has("category") {
Expand Down

0 comments on commit 6816df3

Please sign in to comment.