I'm trying to make a get request in React using javascript fetch, but i can't solve the problem of cors.
The doc of the Api that i'm trying to use is here: "https://docs.abuseipdb.com/#check-endpoint".
Below the code:
export async function getAbuseipInfo(ip, apiKey) {
const baseUrl = "https://api.abuseipdb.com/api/v2/check?ipAddress=";
console.log(baseUrl + ip);
console.log(apiKey);
await fetch(baseUrl + ip, {
method: 'GET',
mode: 'no-cors', //with this in no-cors mode the value Key is not sended and return 401.
headers: {
'Key': apiKey,
'Accept': 'application/json',
'Access-Control-Allow-Methods': '*', //test to allow all but not working.
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*'
},
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
I tried without mode: 'no-corse' but i get the cors block.
Thanks in advance.