add axios

This commit is contained in:
Yath Seanghay 2021-04-05 12:20:49 +07:00
parent c24929f2ce
commit 23b96fbad4
3 changed files with 27 additions and 7 deletions

13
package-lock.json generated
View File

@ -641,6 +641,14 @@
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg=="
},
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"babel-plugin-syntax-jsx": {
"version": "6.18.0",
"resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz",
@ -2035,6 +2043,11 @@
}
}
},
"follow-redirects": {
"version": "1.13.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",

View File

@ -8,6 +8,7 @@
"start": "next start"
},
"dependencies": {
"axios": "^0.21.1",
"next": "10.0.5",
"react": "17.0.1",
"react-dom": "17.0.1",

View File

@ -1,8 +1,14 @@
const axios = require('axios')
module.exports = (req, res) => {
res.json({
body: req.body,
query: req.query,
cookies: req.cookies,
});
};
const { method, body, url } = req.body;
if (method == 'GET') {
const { data } = await axios.get(url);
return res.send(data);
}
if (method == 'POST') {
const { data } = await axios.post(url, body);
return res.send(data);
}
};