From 537f6b1e78afb20078d967f27976ce1911aee24d Mon Sep 17 00:00:00 2001 From: ksgl Date: Mon, 5 Nov 2018 00:07:10 +0300 Subject: [PATCH] cors attempt #2 --- main.go | 1 - server/api/api.go | 9 +++++++++ server/server.go | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9657af1..dd3eef3 100644 --- a/main.go +++ b/main.go @@ -7,5 +7,4 @@ import ( func main() { confPath := "./conf.json" server.Start(confPath) - // } diff --git a/server/api/api.go b/server/api/api.go index e1c8c25..8970080 100644 --- a/server/api/api.go +++ b/server/api/api.go @@ -19,6 +19,15 @@ type Handler struct { DB psql.DatabaseModel } +func (h *Handler) SlashHandler(rw http.ResponseWriter, r *http.Request) { + rw.Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1:3000") + rw.Header().Set("Access-Control-Allow-Headers", "Content-Type") + + rw.WriteHeader(http.StatusOK) + + return +} + func (h *Handler) RegisterHandler(rw http.ResponseWriter, r *http.Request) { user := models.UserCredentials{ Username: r.FormValue("username"), diff --git a/server/server.go b/server/server.go index 84addf8..7be2ab5 100644 --- a/server/server.go +++ b/server/server.go @@ -26,6 +26,7 @@ func Start(path string) { DB: *db, } + r.HandleFunc("/", API.SlashHandler).Methods("GET") r.HandleFunc("/users", API.RegisterHandler).Methods("POST") r.HandleFunc("/users/me", API.GetMeHandler).Methods("GET") r.HandleFunc("/users/me", API.EditMeHandler).Methods("PUT")