summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-29 19:46:43 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-29 19:46:43 -0500
commit30ccc1f1c4a0ba64e16a0ef306f5b4c71df5760f (patch)
tree4fe30d2f8386870ac897792e10187e9b6b0562bb
parent9e1ab63bb039b72cdd2da98c3814366ec1851c7a (diff)
Fix Content-Type header
Content-Type header was not included in response because WriteHeader() was called before setting Content-Type.
-rw-r--r--backend/main.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/backend/main.go b/backend/main.go
index 5ec4ce9..0bd5ebf 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -32,13 +32,13 @@ func MakeAPIResponse(status int, msg string, data interface{}) *APIResponse {
func sendResponse(w http.ResponseWriter, code int, msg string, data interface{}) {
w.Header().Set("Access-Control-Allow-Origin", "*") //Enable CORS
+ w.Header().Set("Content-Type",
+ "application/json; charset=UTF-8")
+
w.WriteHeader(code)
resp := MakeAPIResponse(code, msg, data)
- w.Header().Set("Content-Type",
- "application/json; charset=UTF-8")
-
if err := json.NewEncoder(w).Encode(resp); err != nil {
panic(err)
}