api access controll

This commit is contained in:
Martin Geno 2016-05-17 10:52:39 +02:00
parent 668de8188d
commit a4b947a9b6
1 changed files with 29 additions and 22 deletions

View File

@ -18,10 +18,17 @@ func jsonOutput(w http.ResponseWriter,data interface{}){
} }
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers","Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
w.Write(js) w.Write(js)
} }
func BasicAuth(h httprouter.Handle, pass []byte) httprouter.Handle { func BasicAuth(h httprouter.Handle, pass []byte) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers","Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
const basicAuthPrefix string = "Basic " const basicAuthPrefix string = "Basic "
// Get the Basic Authentication credentials // Get the Basic Authentication credentials