Error in Post Method in JavaScript using Fetch

0

I'm trying to make a Post to send a Push Notification through Expo, this is for an application developed in React native, I'm doing it from Javascript and it sends me this error

Failed to load link : Response to preflight request does not pass access control check: The 'Access-Control-Allow-Origin' header has a value ' link ' that is not equal to the supplied origin. Origin ' link ' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request to 'no-cors' to fetch the resource with CORS disabled.

I uploaded it to my server where I have my page hosted but it sends me the same error this is the code

const config = {
    method: 'POST',
    headers: {

        Accept: "application/json",
        "Accept-Encoding": "gzip,deflate",
        "Content-Type": "application/json"
    },

    body: JSON.stringify({
        "to": "ExponentPushToken[omijKxCLlMs4A_jQn10rnV]",
        "sound": "default",
        "body": "Prueba post"
    })
};


fetch("https://exp.host/--/api/v2/push/send", config)
    .then(res => res.json())
    .then(res => {
        //console.log(res)
        //return res.secure_url
    })
    .catch((err) => {
        //console.log(err)
    })
    
asked by Packvt 19.06.2018 в 17:58
source

1 answer

0

Apparently it was enough to add

    **mode: "no-cors"**,
    method: 'POST',
    headers:
    
answered by 19.06.2018 в 19:07