Browse Source

mise a jour

main
youssef 5 years ago
parent
commit
8d8d5edf14
  1. 61
      index.js
  2. 7011
      package-lock.json
  3. 4221
      yarn.lock

61
index.js

@ -3,6 +3,61 @@ import fastify from 'fastify';
import axios from 'axios'; import axios from 'axios';
const app = fastify({ logger: true }); const app = fastify({ logger: true });
var facts = {};
var fox = {};
var res = {};
function getFacts() {
return axios.get('https://cat-fact.herokuapp.com/facts');
}
let promise1 = new Promise((resolve, reject) => {
axios.get('https://cat-fact.herokuapp.com/facts').then(function(result) {
return result;
});
});
function getFox() {
return axios.get('https://randomfox.ca/floof/');
}
function first() {
Promise.all([getFacts(), getFox()])
.then(function (results) {
const acct = results[0];
const perm = results[1];
//console.log(acct['data'][1]['text']);
//console.log(perm['data']['image']);
creationJson(acct, perm);
});
}
function creationJson(fact,fox){
facts = fact;
let companies =
`[
{
"foxPicture": `+fox['data']['image']+`,
"catFacts": [
`+fact['data'][1]['text']+
fact['data'][2]['text']+
fact['data'][3]['text']+`
],
"ceo": "Neil",
"rating": 3.6
},
{
"name": "Small startup",
"numberOfEmployees": 10,
"ceo": null,
"rating": 4.3
}
]`
return companies;
}
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
return { return {
@ -12,6 +67,12 @@ app.get('/', async (req, res) => {
}; };
}); });
app.get('/facts',async (req, res) => {
return creationJson();
});
// Run the server! // Run the server!
const start = async () => { const start = async () => {
try { try {

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