Browse Source

denisjunior

add files
main
denisdalmeida04@gmail.com 5 years ago
parent
commit
964c6e2f57
  1. 61
      index.js
  2. 7010
      package-lock.json
  3. 4220
      yarn.lock

61
index.js

@ -5,11 +5,7 @@ import axios from 'axios';
const app = fastify({ logger: true });
app.get('/', async (req, res) => {
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
};
return getData();
});
// Run the server!
@ -21,4 +17,59 @@ const start = async () => {
process.exit(1);
}
};
//get a cat fact
const getCatFact = (base) => {
return new Promise(resolve => {
axios.get(`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&base=`+ base).then(response => {
const data = response.data;
let tab = [];
for (let i =0; i<data.length; i++){
tab.push(data[i].text);
}
resolve(tab);
}).catch(error =>{
resolve(null);
})
});
};
// get a fox image
const getFox = () => {
return new Promise(resolve => {
axios.get(`https://randomfox.ca/floof/`).then(response => {
const data = response.data;
resolve(data.image);
}).catch(error => {
resolve(null);
})
});
};
// get country day off
const getDay = (country) =>{
return new Promise(resolve => {
axios.get(`https://date.nager.at/api/v2/PublicHolidays/2021/` + country).then(response => {
const data = response.data;
resolve(data);
}).catch(error => {
resolve(null);
})
});
};
//
const getData = () => {
const cat = getCatFact(3);
const foxImage= getFox();
const day = getDay('FR');
return Promise.all([cat, foxImage, day]).then((values) => {
let val = {}
val['catFacts'] = values[0];
val['foxPicture']= values[1];
val['holidays']= values[2];
return val;
})
}
start();

7010
package-lock.json
File diff suppressed because it is too large
View File

4220
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save