0

Estoy tratando de realizar un Post para mandar una Push Notification mediante Expo, esto para una aplicación desarrollada en React native, lo estoy realizando desde Javascript y me manda este error

Failed to load https://exp.host/--/api/v2/push/send: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://expo.io' that is not equal to the supplied origin. Origin 'http://127.0.0.1:62697' 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's mode to 'no-cors' to fetch the resource with CORS disabled.

lo subi a mi servidor donde tengo alojada mi pagina pero me manda el mismo error este es el codigo

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)
    })
2
  • Tienes un problema con CORS: ese API está diseñada pensando en que tu servidor haga peticiones, no una aplicación desde un navegador, por lo que no implementa CORS y no podrás leer las respuestas el 19 jun. 2018 a las 16:12
  • Gracias.. al parecer solo bastaba con agregar mode: "no-cors", en la constante de configuracion.
    – Packvt
    el 19 jun. 2018 a las 17:05

1 respuesta 1

0

Al parecer bastaba con agregar

    **mode: "no-cors"**,
    method: 'POST',
    headers:

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.