|
|
@ -3,13 +3,13 @@ import fastify from 'fastify'; |
|
|
import axios from 'axios'; |
|
|
import axios from 'axios'; |
|
|
|
|
|
|
|
|
const app = fastify({ logger: true }); |
|
|
const app = fastify({ logger: true }); |
|
|
const URLHOLIDAYS = `https://date.nager.at/api/v2/PublicHolidays/2021/TN`; |
|
|
|
|
|
|
|
|
const URLHOLIDAYS = `https://date.nager.at/api/v2/PublicHolidays/2021/`; |
|
|
const URLCATFACTS= `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`; |
|
|
const URLCATFACTS= `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`; |
|
|
const URLFOX = `https://randomfox.ca/floof/`; |
|
|
const URLFOX = `https://randomfox.ca/floof/`; |
|
|
|
|
|
|
|
|
const getCatFacts = async () => { |
|
|
const getCatFacts = async () => { |
|
|
try{ |
|
|
try{ |
|
|
const response = await axios.get(URLANIMALS); |
|
|
|
|
|
|
|
|
const response = await axios.get(URLCATFACTS); |
|
|
const json = await response.data.map(cats=>cats.text); |
|
|
const json = await response.data.map(cats=>cats.text); |
|
|
return json; |
|
|
return json; |
|
|
}catch(err){ |
|
|
}catch(err){ |
|
|
@ -39,13 +39,20 @@ const getHolidays = async(country)=>{ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app.get('/request', async (req, res) => { |
|
|
|
|
|
const [catFacts,foxPicture,holidays]= |
|
|
|
|
|
await Promise.all([getCatFacts(),getFox(),getHolidays("FR")]) |
|
|
|
|
|
return { |
|
|
|
|
|
foxPicture,catFacts,holidays, |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
app.get('/', async (req, res) => { |
|
|
app.get('/', async (req, res) => { |
|
|
return { |
|
|
return { |
|
|
message: "Welcome to your projet" |
|
|
message: "Welcome to your projet" |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Run the server!
|
|
|
|
|
|
const start = async () => { |
|
|
const start = async () => { |
|
|
try { |
|
|
try { |
|
|
await app.listen(8090); |
|
|
await app.listen(8090); |
|
|
|