Closed flashios09 closed 1 year ago
Hi,
Even with the PR https://github.com/chirpstack/chirpstack-rest-api/pull/5, the CORS still not working properly
I had to update the run function:
run
func run() error { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() r := mux.NewRouter() gatewayHandler, err := getGatewayHandler(ctx) if err != nil { return err } r.PathPrefix("/api/").Handler(gatewayHandler) r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data, err := ui.FS.ReadFile("index.html") if err != nil { w.WriteHeader(http.StatusInternalServerError) return } w.Write(data) }) r.PathPrefix("/").Handler(http.FileServer(http.FS(ui.FS))) corsObj := handlers.AllowedOrigins([]string{*cors}) // 1. Add the allowed methods header corsMethods := handlers.AllowedMethods([]string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}) // 2. Add the allowed headers corsHeaders := handlers.AllowedHeaders([]string{"Content-Type", "Authorization"}) // 3. Update the handlers.CORS params return http.ListenAndServe(*bind, handlers.CORS(corsObj, corsMethods, corsHeaders)(r)) }
Now it's working:
I can create a PR :)
Hi,
Even with the PR https://github.com/chirpstack/chirpstack-rest-api/pull/5, the CORS still not working properly
I had to update the
run
function:Now it's working:
I can create a PR :)