add cors; add username to signup interface
This commit is contained in:
22
main.go
22
main.go
@@ -20,7 +20,7 @@ func main() {
|
||||
AddDefaultCustomer(nkodeApi)
|
||||
handler := model.NKodeHandler{Api: &nkodeApi}
|
||||
mux := http.NewServeMux()
|
||||
//mux.Handle(api.CreateNewCustomer, &handler)
|
||||
mux.Handle(api.CreateNewCustomer, &handler)
|
||||
mux.Handle(api.GenerateSignupInterface, &handler)
|
||||
mux.Handle(api.SetNKode, &handler)
|
||||
mux.Handle(api.ConfirmNKode, &handler)
|
||||
@@ -28,7 +28,25 @@ func main() {
|
||||
mux.Handle(api.Login, &handler)
|
||||
mux.Handle(api.RenewAttributes, &handler)
|
||||
fmt.Println("Running on localhost:8080...")
|
||||
log.Fatal(http.ListenAndServe("localhost:8080", mux))
|
||||
log.Fatal(http.ListenAndServe("localhost:8080", corsMiddleware(mux)))
|
||||
}
|
||||
|
||||
func corsMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Set the CORS headers
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
|
||||
// Handle preflight requests
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
// Call the next handler
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func AddDefaultCustomer(api nkode.NKodeAPI) {
|
||||
|
||||
Reference in New Issue
Block a user