|
|
|
@ -4,11 +4,32 @@ import axios from 'axios'; |
|
|
|
|
|
|
|
const app = fastify({ logger: true }); |
|
|
|
|
|
|
|
const CAT_FACT_URL = 'https://cat-fact.herokuapp.com/facts/random' |
|
|
|
const RANDOM_FOX_URL = 'https://randomfox.ca/floof/' |
|
|
|
const COUNTRY_HOLIDAYS_URL = 'https://date.nager.at/api/v3/publicholidays/2022/' |
|
|
|
|
|
|
|
const getCatFacts = async (amount) => await axios.get(CAT_FACT_URL + '?amount=' + amount) |
|
|
|
.then((response) => response.data.map(item => item.text)) |
|
|
|
.catch(() => null) |
|
|
|
|
|
|
|
const getFoxPicture = async () => await axios.get(RANDOM_FOX_URL) |
|
|
|
.then((response) => response.data.image) |
|
|
|
.catch(() => null) |
|
|
|
|
|
|
|
|
|
|
|
const getCountryHolidays = async (countryCode) => await axios.get(COUNTRY_HOLIDAYS_URL + countryCode) |
|
|
|
.then((response) => response.data) |
|
|
|
.catch(() => null) |
|
|
|
|
|
|
|
|
|
|
|
app.post('/', async (req, res) => { |
|
|
|
let catFacts = await getCatFacts(3) |
|
|
|
let foxPicture = await getFoxPicture() |
|
|
|
let holidays = await getCountryHolidays(req.body?.countryCode ?? "FR") |
|
|
|
return { |
|
|
|
message: `Welcome to Node Babel with ${ |
|
|
|
req.body?.testValue ?? 'no testValue' |
|
|
|
}`,
|
|
|
|
foxPicture, |
|
|
|
catFacts, |
|
|
|
holidays, |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|