|
|
@ -4,29 +4,46 @@ import axios from 'axios'; |
|
|
const app = fastify({ logger: true }); |
|
|
const app = fastify({ logger: true }); |
|
|
|
|
|
|
|
|
app.get('/', async (req, res) => { |
|
|
app.get('/', async (req, res) => { |
|
|
return { |
|
|
|
|
|
catfacts: getCatFacts(), |
|
|
|
|
|
foxes: getFoxDay(), |
|
|
|
|
|
day: getDayOfCountry() |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
return getAll(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const getCatFacts = async(id) =>{ |
|
|
|
|
|
axios.get('https://cat-fact.herokuapp.com/facts/{id}').then(res => {}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getCatFacts = () =>{ |
|
|
|
|
|
let facts = []; |
|
|
|
|
|
return new Promise(resolve => {axios.get('https://cat-fact.herokuapp.com/facts').then(res => { |
|
|
|
|
|
let facts = []; |
|
|
|
|
|
let i = 0; |
|
|
|
|
|
while (i < 3) { |
|
|
|
|
|
facts.push(res.data[i].text); |
|
|
|
|
|
i++; |
|
|
|
|
|
}; |
|
|
|
|
|
resolve(facts); |
|
|
|
|
|
});}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const getFoxDay = () =>{ |
|
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
|
axios.get('https://randomfox.ca/floof/').then(res => {resolve(res.data.image)}); |
|
|
|
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const getFoxDay = async(id) =>{ |
|
|
|
|
|
axios.get('https://randomfox.ca/floof/').then(res => {}); |
|
|
|
|
|
|
|
|
const getDayOfCountry = () => { |
|
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
|
axios.get('https://date.nager.at/api/v2/publicholidays/2019/FR').then(res => {resolve(res.data)}); |
|
|
|
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const getDayOfCountry = async(id) =>{ |
|
|
|
|
|
axios.get('https://randomfox.ca/floof/').then(res => {}); |
|
|
|
|
|
|
|
|
const getAll = () => { |
|
|
|
|
|
let promises = Promise.all([getCatFacts(),getFoxDay(),getDayOfCountry()]); |
|
|
|
|
|
console.log([promises[1]]); |
|
|
|
|
|
let data = promises |
|
|
|
|
|
return data; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const start = async () => { |
|
|
const start = async () => { |
|
|
try { |
|
|
try { |
|
|
await app.listen(5000); |
|
|
await app.listen(5000); |
|
|
getCatFacts(1); |
|
|
|
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
app.log.error(err); |
|
|
app.log.error(err); |
|
|
process.exit(1); |
|
|
process.exit(1); |
|
|
|