Browse Source

💩 work in progress / get almost good

main
guidezSeb 5 years ago
parent
commit
54562d2dee
  1. 57
      index.js
  2. 7011
      package-lock.json
  3. 4221
      yarn.lock

57
index.js

@ -2,14 +2,56 @@ import fastify from 'fastify';
// see axios doc on how to use it
import axios from 'axios';
const app = fastify({ logger: true });
const app = fastify({
logger: true
});
app.get('/', async (req, res) => {
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
};
// app.get('/', async (req, res) => {
// return {
// message: `Welcome to Node Babel with ${
// req.body?.testValue ?? 'no testValue'
// }`,
// };
// });
const promise1 = new Promise((resolve => {
axios.get("https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3")
.then((response) => {
let tab = [];
for (let i = 0; i < response.data.length; i++) {
tab.push(response.data[i].text);
}
resolve(tab);
})
})).catch(error => resolve(null));
const promise2 = new Promise((resolve => {
axios.get("https://randomfox.ca/floof/")
.then((response) => {
resolve(response.data.image);
})
})).catch(error => resolve(null));
const promise3 = new Promise((resolve => {
axios.get("https://date.nager.at/Api/v2/NextPublicHolidays/FR")
.then((response) => {
resolve(response.data);
})
})).catch(error => resolve(null));
const fetchAsyncData = async () => {
let tab = {}
return Promise.all([promise1, promise2, promise3]).then(res => {
tab['foxPicture'] = res[1];
tab['catFacts'] = res[0];
tab['holidays'] = res[2];
return tab;
})
}
//API CAT
app.get('/', async () => {
return fetchAsyncData();
});
// Run the server!
@ -19,6 +61,7 @@ const start = async () => {
} catch (err) {
app.log.error(err);
process.exit(1);
}
};
start();

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

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

Loading…
Cancel
Save