diff --git a/index.js b/index.js index 91e7f05..d214261 100644 --- a/index.js +++ b/index.js @@ -4,16 +4,6 @@ import axios from 'axios'; const app = fastify({ logger: true }); -function timeout(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - -// const getCat = async () => { -// console.log('toto'); -// let response = await axios.get(`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`) -// .then(res => response.json()); -// }; - async function getCat() { const response = await axios.get("https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3"); const data = await response.data; @@ -21,11 +11,19 @@ async function getCat() { return text; } +async function getFox() { + const response = await axios.get("https://randomfox.ca/floof/"); + const image = await response.data.image; + return image; +} + app.post('/', async (req, res) => { const catInfos = await getCat(); + const foxImage = await getFox(); return { message: `Welcome to Node Babel`, - catFacts: catInfos + catFacts: catInfos, + fox: foxImage, }; });