I am doing little project to learn and put it in my project section I get problem like this:
GET https://cors-anywhere.herokuapp.com/http://www.recipepuppy.com/api/?q=rice 500 (Internal Server Error)
Uncaught (in promise) Error: Request failed with status code 500 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:61)
I tried with using axios headers (i found this sugestion on another forum but it dosn't work) My code for fetching data looks like this
export async function fetchData(text) {
const proxy = `https://cors-anywhere.herokuapp.com/`;
const base = `http://www.recipepuppy.com/api/`;
const baseEnd = `q=${text}`;
const data = await axios
.get(`${proxy}${base}?${baseEnd}`)
.then(data =>console.log(data));
const recipes = data.data.results;
return recipes.length > 0 ? recipes : false;
}
function called here:
async function getRecipes(e){
e.preventDefault();
const text = e.target[1].value;
const loader = '<div class="loader"></div>';
container.insertAdjacentHTML('beforebegin', loader);
const recipes = await fetchData(text);
document.querySelector('.loader').remove();
displayRecipes(recipes);
}
export async function fetchData(text) { const proxy =
cors-anywhere.herokuapp.com; const base =
recipepuppy.com/api?; const baseEnd =
q=${text}; const data = await axios.get(
${proxy}${base}?${baseEnd}).catch(err => console.log(err)); console.log(data) return recipes.length > 0 ? recipes : false; }
and this is where i call the function ` – Creativelessasync function getRecipes(e){ e.preventDefault(); const text = e.target[1].value; const loader = '<div class="loader"></div>'; container.insertAdjacentHTML('beforebegin', loader); const recipes = await fetchData(text); document.querySelector('.loader').remove(); displayRecipes(recipes); }
– Creativeless