Browse Source

last commit

main
hallouma875 5 years ago
parent
commit
dc45b827e1
  1. 13
      index.js

13
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);

Loading…
Cancel
Save