Browse Source

TP FINIS

main
Tarskan 4 years ago
parent
commit
cec0e29a4e
  1. 48
      index.js
  2. 8535
      package-lock.json
  3. 5015
      yarn.lock

48
index.js

@ -5,13 +5,55 @@ import axios from 'axios';
const app = fastify({ logger: true });
app.post('/', async (req, res) => {
const foxPicture = await getFoxPicturet()
const catFacts = await getCatsFacts()
const holliday = await getHolliday(req.body?.countryCode)
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
foxPicture: foxPicture,
catFacts: catFacts ,
holidays: holliday
};
});
app.post('/cats', async (req, res) => {
return getCatsFacts()
});
app.post('/fox', async (req, res) => {
return getFoxPicturet()
});
app.post('/holliday', async (req, res) => {
return getHolliday(req.body?.countryCode)
});
async function getCatsFacts() {
try {
var catFacts = (await axios.get('https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3')).data
return catFacts.map(cat => cat.text)
} catch (error) {
return null
}
}
async function getFoxPicturet() {
try {
var foxPicture = (await axios.get('https://randomfox.ca/floof/')).data
return foxPicture.image
} catch (error) {
return null
}
}
async function getHolliday(countryCode) {
try {
return (await axios.get('https://date.nager.at/api/v3/publicholidays/2022/' + countryCode)).data
} catch (error) {
return null
}
}
// Only used for dev server, do not remove
app.head('/', () => ({ ping: 'pong' }));

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

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

Loading…
Cancel
Save