Skip to content

Commit

Permalink
🐞 fix(utils): 在node内运行axios,需要屏蔽掉代理,避免请求失败。
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-cat committed Dec 27, 2024
1 parent bef2295 commit eb21028
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/utils/src/tests/mall-apifox-port/simple-axios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,30 @@ import axios from "axios";
function createAxiosInstance() {
const instance = axios.create({
baseURL: "https://pcapi-xiaotuxian-front-devtest.itheima.net",

/** 请求超时时间 */
timeout: 10000,

/** 允许跨域 */
// withCredentials: true,
});

// 使用qs序列化参数params参数
// instance.defaults.paramsSerializer = function (params) {
// return qs.stringify(params);
// };

/**
* 在node内运行axios,需要屏蔽掉代理,避免请求失败。
* @see https://github.com/axios/axios/issues/925
* @see https://stackoverflow.com/questions/77258713/400-the-plain-http-request-was-sent-to-https-port-in-node-js
*/
proxy: false,
});
return instance;
}

function main() {
axios
.get(
//
//
"https://pcapi-xiaotuxian-front-devtest.itheima.net/home/category/head",
// "https://pcapi-xiaotuxian-front-devtest.itheima.net/home/hot"
)
const instance = createAxiosInstance();
instance
.get("/home/category/head")
.then((res) => {
console.log(" ? ", res);
console.log(" ? ", res.data);
})
.catch((error) => {
console.error("Request failed", error);
});
}

Expand Down

0 comments on commit eb21028

Please sign in to comment.