From c5216f32b956d7a71f8084e3ee1992b927c574e5 Mon Sep 17 00:00:00 2001 From: mlctrez Date: Thu, 24 Mar 2022 17:50:45 -0500 Subject: [PATCH] no-cors when in wasm --- client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index dfc8059..0faedeb 100644 --- a/client.go +++ b/client.go @@ -12,6 +12,7 @@ import ( "git.mills.io/prologic/msgbus" msgbus_client "git.mills.io/prologic/msgbus/client" "github.com/keys-pub/keys" + "github.com/maxence-charriere/go-app/v9/pkg/app" log "github.com/sirupsen/logrus" "go.mills.io/salty" @@ -29,7 +30,11 @@ func PackMessage(me *Addr, msg string) []byte { // Send sends the encrypted message `msg` to the Endpoint `endpoint` using a // `POST` request and returns nil on success or an error on failure. func Send(endpoint, msg string) error { - res, err := Request(http.MethodPost, endpoint, nil, bytes.NewBufferString(msg)) + headers := make(http.Header) + if app.IsClient { + headers.Add("js.fetch:mode", "no-cors") + } + res, err := Request(http.MethodPost, endpoint, headers, bytes.NewBufferString(msg)) if err != nil { return fmt.Errorf("error publishing message to %s: %w", endpoint, err) }