|
|
@ -6,62 +6,56 @@ const app = fastify({ logger: true }); |
|
|
|
|
|
|
|
|
let requestCat = async () => { |
|
|
let requestCat = async () => { |
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
const cat = await axios.get(`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`); |
|
|
|
|
|
|
|
|
const cat = await axios.get( |
|
|
|
|
|
`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3` |
|
|
|
|
|
); |
|
|
|
|
|
console.log(cat); |
|
|
const fact = cat.data.map((cat) => { |
|
|
const fact = cat.data.map((cat) => { |
|
|
return cat.text; |
|
|
return cat.text; |
|
|
}); |
|
|
}); |
|
|
return fact; |
|
|
return fact; |
|
|
|
|
|
|
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
console.log("Error"); |
|
|
|
|
|
|
|
|
console.log('Error'); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
let requestFox = async () => { |
|
|
let requestFox = async () => { |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const fox = await axios.get('https://randomfox.ca/floof/'); |
|
|
|
|
|
|
|
|
const fox = await axios.post('https://randomfox.ca/floof/'); |
|
|
return fox.data.image; |
|
|
return fox.data.image; |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
console.log("Error"); |
|
|
|
|
|
|
|
|
console.log('Error'); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let requestHolidays = async (countryCode = 'FR') => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let requestHolidays = async () => { |
|
|
try { |
|
|
try { |
|
|
const holidays = await axios.get(`https://date.nager.at/api/v2/PublicHolidays/2021/${countryCode}`); |
|
|
|
|
|
|
|
|
const holidays = await axios.get( |
|
|
|
|
|
`https://date.nager.at/api/v2/PublicHolidays/2021/fr` |
|
|
|
|
|
); |
|
|
return holidays.data; |
|
|
return holidays.data; |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
console.log("Error"); |
|
|
|
|
|
|
|
|
console.log('Error'); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
let fetchApis = async (countryCode) =>{ |
|
|
|
|
|
|
|
|
let fetchApis = async () => { |
|
|
const catFacts = await requestCat(); |
|
|
const catFacts = await requestCat(); |
|
|
const foxPicture = await requestFox(); |
|
|
const foxPicture = await requestFox(); |
|
|
const holidays = await requestHolidays(countryCode); |
|
|
|
|
|
|
|
|
const holidays = await requestHolidays(); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
foxPicture: foxPicture, |
|
|
foxPicture: foxPicture, |
|
|
catFacts: catFacts, |
|
|
catFacts: catFacts, |
|
|
holidays: holidays |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
holidays: holidays, |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
app.post('/', async (req, res) => { |
|
|
app.post('/', async (req, res) => { |
|
|
|
|
|
|
|
|
return await fetchApis(req.body.countryCode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await fetchApis(req.body); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Run the server!
|
|
|
// Run the server!
|
|
|
|