summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-07-10 22:16:43 +0200
committerAki <please@ignore.pl>2020-07-10 22:16:43 +0200
commit9c4f3043d13f09e5dd9f5c5c6e51dc185dce91fd (patch)
tree124e97f32fa9c06032055e120e7f8c8b7da6d88a
parent9bce1d278b367feb00b1be4c46881489dab4c36a (diff)
downloadrudone-9c4f3043d13f09e5dd9f5c5c6e51dc185dce91fd.zip
rudone-9c4f3043d13f09e5dd9f5c5c6e51dc185dce91fd.tar.gz
rudone-9c4f3043d13f09e5dd9f5c5c6e51dc185dce91fd.tar.bz2
Added cross-origin policies
-rw-r--r--main.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/main.go b/main.go
index 1b5dd5b..c521203 100644
--- a/main.go
+++ b/main.go
@@ -7,7 +7,18 @@ import (
"net/http"
)
-func handleEntry(w http.ResponseWriter, r *http.Request) {
+func handleEntryOptions(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Methods", "POST")
+ w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
+ w.WriteHeader(http.StatusNoContent)
+}
+
+func handleEntryPost(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+ w.Header().Set("Access-Control-Allow-Methods", "POST")
+ w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
+
var entry Entry
err := json.NewDecoder(r.Body).Decode(&entry)
@@ -25,7 +36,8 @@ func handleEntry(w http.ResponseWriter, r *http.Request) {
func handleRequests() {
router := mux.NewRouter()
- router.HandleFunc("/entry", handleEntry).Methods("POST")
+ router.HandleFunc("/entry", handleEntryPost).Methods("POST")
+ router.HandleFunc("/entry", handleEntryOptions).Methods("OPTIONS")
log.Fatal(http.ListenAndServe(":8080", router))
}