Skip to content

Commit

Permalink
cors attempt #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ksgl committed Nov 4, 2018
1 parent dfa1a0a commit 537f6b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import (
func main() {
confPath := "./conf.json"
server.Start(confPath)
//
}
9 changes: 9 additions & 0 deletions server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 537f6b1

Please sign in to comment.