Closed Kahoulam closed 5 months ago
The issue with the CORS error on the POST /multiply endpoint has been resolved by configuring CORS globally in the goa.design API. Here is the solution that worked:
cors.Origin("*", func() {
cors.Headers("Authorization", "Content-Type")
cors.Methods("POST",
})
Description:
I'm experiencing a CORS error when trying to use the POST method in the generated API through the Swagger UI. The GET method works fine, but when I try to use the POST method, I get the following error:
Steps to Reproduce:
Code
import ( "calc/gen/calc" "calc/gen/http/calc/server" "context" "net/http"
)
type svc struct{}
func (s svc) Multiply(ctx context.Context, p calc.MultiplyPayload) (int, error) { return p.A * p.B, nil }
func (s svc) Add(ctx context.Context, p calc.AddPayload) (res int, err error) { return p.A + p.B, nil }
func main() { s := &svc{} endpoints := calc.NewEndpoints(s) mux := goahttp.NewMuxer() dec := goahttp.RequestDecoder enc := goahttp.ResponseEncoder svr := server.New(endpoints, mux, dec, enc, nil, nil) server.Mount(mux, svr) httpsvr := &http.Server{ Addr: "localhost:8000", Handler: mux, } if err := httpsvr.ListenAndServe(); err != nil { panic(err) } }