doc: add getChinaData method

This commit is contained in:
Leon Xu committed 2022-04-12 12:38:07 -07:00
1 parent 7502eba284
commit 4e7ed46e26
1 file changed
+24
+24
View File
@@ -0,0 +1,24 @@
import axios from "axios";
import dotenv from "dotenv";
import path from "path";
dotenv.config({
path: path.dirname("../.env"),
});
// Get China Data method
export const getChinaData = async (req, res) => {
// 导入环境变量
const { tianapiKey } = process.env;
const ncovChinaUrl = `https://api.tianapi.com/ncov/index?key=${tianapiKey}`;
try {
axios.get(ncovChinaUrl).then((result) => {
const { data } = result;
let parseData = data;
res.status(200).json(data);
// 写入获取数据到数据库
});
} catch (error) {
res.status(404).json({ message: error });
}
};