|
|
|
@ -4,13 +4,30 @@ import axios from 'axios'; |
|
|
|
|
|
|
|
const app = fastify({ logger: true }); |
|
|
|
|
|
|
|
app.post('/', async (req, res) => { |
|
|
|
|
|
|
|
|
|
|
|
const getFoxImg = () => axios.get('https://randomfox.ca/floof/').then(resp => resp.data.image).catch(() => null); |
|
|
|
|
|
|
|
|
|
|
|
const getCatFacts = (nb) => axios.get( `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=${nb}`).then(resp => resp.data.map(catInfo => catInfo.text)).catch(() => null ); |
|
|
|
|
|
|
|
|
|
|
|
const getHolidays = (year , contryCode) => axios.get( `https://date.nager.at/api/v3/publicholidays/${year}/${contryCode}`).then(resp => resp.data).catch(() => null); |
|
|
|
|
|
|
|
|
|
|
|
app.post('/' , async (req, res) => { |
|
|
|
let imgFox = await getFoxImg(); |
|
|
|
let catFacts = await getCatFacts(3); |
|
|
|
let holidays = await getHolidays(2022 ,req.body.countryCode); |
|
|
|
return { |
|
|
|
message: `Welcome to Node Babel with ${ |
|
|
|
req.body?.testValue ?? 'no testValue' |
|
|
|
}`,
|
|
|
|
imgFox, |
|
|
|
catFacts, |
|
|
|
holidays |
|
|
|
}; |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only used for dev server, do not remove
|
|
|
|
app.head('/', () => ({ ping: 'pong' })); |
|
|
|
|