Adding CORS headers

This commit is contained in:
Jordi
2019-02-05 13:42:11 +01:00
parent 6551f598cf
commit 144221908b
2 changed files with 13 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ Reference implementation of a voting census service running on the Vocdoni platf
In a GO ready environment:
```
go get -u github.com/vocdoni/dvote-census
go get -u github.com/vocdoni/dvote-census/...
go build -o censusHttpService github.com/vocdoni/dvote-census/cmd/censushttp
```

View File

@@ -71,7 +71,19 @@ func checkAuth(timestamp, signature, message string) bool {
return false
}
func addCorsHeaders(w *http.ResponseWriter, req *http.Request) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
(*w).Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
(*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
}
func claimHandler(w http.ResponseWriter, req *http.Request, op string) {
addCorsHeaders(&w, req)
if (*req).Method == "OPTIONS" {
return
}
var c Claim
var resp Result
if ok := checkRequest(w, req); !ok {