From 7ab5d7dbbfdd1fc4e62e3a5d22f76bb2e36f9269 Mon Sep 17 00:00:00 2001 From: aixianling Date: Tue, 25 Feb 2025 18:02:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=20http=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=A8=A1=E5=9D=97=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 http 工具模块,用于创建带有基础 URL 的 axios 实例 - 更新 package.json,添加 axios 依赖 - 调整 addClient.js 文件的格式 --- api/addClient.js | 4 ++-- package.json | 3 ++- utils/http.js | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 utils/http.js diff --git a/api/addClient.js b/api/addClient.js index 9eac8f4..922dd96 100644 --- a/api/addClient.js +++ b/api/addClient.js @@ -1,6 +1,6 @@ -module.exports = (ctx) => { - + +module.exports = (ctx) => { ctx.body = { message: 'Example POST API', data: ctx.request.body diff --git a/package.json b/package.json index dca6e3f..904b132 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "kubbo", "license": "ISC", "dependencies": { + "axios": "^1.7.9", "dotenv": "^16.4.7", "jsonwebtoken": "^9.0.2", "koa": "^2.15.4", @@ -18,4 +19,4 @@ "koa-router": "^13.0.1", "nodemon": "^3.0.2" } -} \ No newline at end of file +} diff --git a/utils/http.js b/utils/http.js new file mode 100644 index 0000000..7c03ecb --- /dev/null +++ b/utils/http.js @@ -0,0 +1,3 @@ +require("dotenv").config(); +const { default: axios } = require("axios"); +module.exports = (baseURL = process.env.BASE_URL) => axios.create({ baseURL: BASE_URL });