From dc45b827e1171ea1eb96e7073d1f395dee329360 Mon Sep 17 00:00:00 2001 From: hallouma875 Date: Wed, 17 Feb 2021 18:02:01 +0100 Subject: [PATCH] last commit --- index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0f93db1..7699df6 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ import fastify from 'fastify'; import axios from 'axios'; 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 URLFOX = `https://randomfox.ca/floof/`; const getCatFacts = async () => { try{ - const response = await axios.get(URLANIMALS); + const response = await axios.get(URLCATFACTS); const json = await response.data.map(cats=>cats.text); return json; }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) => { return { message: "Welcome to your projet" }; }); -// Run the server! const start = async () => { try { await app.listen(8090);