Browse Source

Adding CORS headers

feature_chain_module
Jordi 5 years ago
parent
commit
144221908b
2 changed files with 13 additions and 1 deletions
  1. +1
    -1
      cmd/censushttp/README.md
  2. +12
    -0
      service/censusmanager.go

+ 1
- 1
cmd/censushttp/README.md

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

+ 12
- 0
service/censusmanager.go

@ -71,7 +71,19 @@ func checkAuth(timestamp, signature, message string) bool {
return false 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) { func claimHandler(w http.ResponseWriter, req *http.Request, op string) {
addCorsHeaders(&w, req)
if (*req).Method == "OPTIONS" {
return
}
var c Claim var c Claim
var resp Result var resp Result
if ok := checkRequest(w, req); !ok { if ok := checkRequest(w, req); !ok {

Loading…
Cancel
Save