Browse Source

massive update from local work

main
Droissart Nicolas 5 years ago
parent
commit
01a1b06bd9
  1. 58
      index.js
  2. 7011
      package-lock.json
  3. 4221
      yarn.lock

58
index.js

@ -2,23 +2,57 @@ import fastify from 'fastify';
// see axios doc on how to use it // see axios doc on how to use it
import axios from 'axios'; import axios from 'axios';
const app = fastify({ logger: true });
const app = fastify({logger: true});
const getCatFacts = async (catFactsAmount) => {
try {
return (await axios.get(`https://cat-fact.herokuapp.com/facts/random?amount=${catFactsAmount}`)).data
.map(fact => fact.text)
} catch (e) {
return null
}
}
const getFoxImage = async () => {
try {
return (await axios.get('https://randomfox.ca/floof/')).data.image
} catch (e) {
return null
}
}
const getHolidays = async (countryCode) => {
try {
return (await axios.get(`https://date.nager.at/api/v2/PublicHolidays/2021/${countryCode}`)).data
} catch (e) {
return null
}
}
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
};
return {
'foxPicture': await getFoxImage(),
'catFacts': await getCatFacts(3),
'holidays': await getHolidays(req.params.countryCode)
};
});
app.post('/', async (req, res) => {
return {
'foxPicture': await getFoxImage(),
'catFacts': await getCatFacts(3),
'holidays': await getHolidays(req.body.countryCode)
};
}); });
// Run the server! // Run the server!
const start = async () => { const start = async () => {
try {
await app.listen(5000);
} catch (err) {
app.log.error(err);
process.exit(1);
}
try {
await app.listen(5000);
} catch (err) {
app.log.error(err);
process.exit(1);
}
}; };
start(); 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