Skip to content

Commit

Permalink
add origin header to json response handler
Browse files Browse the repository at this point in the history
  • Loading branch information
0c34 committed Nov 2, 2017
1 parent 587f539 commit c2c7406
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion util/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ func SafeRender(w http.ResponseWriter, r *http.Request, name string, data map[st
}

func RenderAsJson(w http.ResponseWriter, data ...interface{}) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET")
w.Header().Set("Content-Type", "application/json")
b, err := json.Marshal(data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(b)
return
}

func UnSafeRender(w http.ResponseWriter, name string, data ...interface{}) {
Expand Down

0 comments on commit c2c7406

Please sign in to comment.