6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-28 17:51:04 +00:00

no-cors when in wasm

This commit is contained in:
mlctrez 2022-03-24 17:50:45 -05:00
parent 43f5d14025
commit c5216f32b9

@ -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)
}