diff --git a/index.js b/index.js index a282a8e..0f93db1 100644 --- a/index.js +++ b/index.js @@ -3,19 +3,52 @@ import fastify from 'fastify'; import axios from 'axios'; const app = fastify({ logger: true }); +const URLHOLIDAYS = `https://date.nager.at/api/v2/PublicHolidays/2021/TN`; +const URLCATFACTS= `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`; +const URLFOX = `https://randomfox.ca/floof/`; + +const getCatFacts = async () => { + try{ + const response = await axios.get(URLANIMALS); + const json = await response.data.map(cats=>cats.text); + return json; + }catch(err){ + console.log(err); + return null; + } +}; + +const getFox = async()=>{ + try{ + const response = await axios.get(URLFOX); + const json = await response.data.image; + return json; + }catch(err){ + console.log(err); + return null; + } +} +const getHolidays = async(country)=>{ + try{ + const response = await axios.get(`${URLHOLIDAYS}${country}`); + const data = await response.data; + return data; + }catch(err){ + console.error(err); + return null; + } +} app.get('/', async (req, res) => { return { - message: `Welcome to Node Babel with ${ - req.body?.testValue ?? 'no testValue' - }`, + message: "Welcome to your projet" }; }); // Run the server! const start = async () => { try { - await app.listen(5000); + await app.listen(8090); } catch (err) { app.log.error(err); process.exit(1); diff --git a/package.json b/package.json index 620e7c7..a3121ca 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,12 @@ "pretty-quick": "3.1.0" }, "scripts": { - "start": "nodemon exec babel-node index.js", + "start": "node --experimental-modules index.js ", "format:write": "prettier --write \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"", "format:check": "prettier --list-different \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"" }, "engines": { - "node": ">=14" + "node": "12.16.1" }, "type": "module", "husky": {