Node 环境下 axios 的 proxy 配置—— https-proxy-agent

    这个我还没有想清楚原理是什么,但是可以访问… app.js 端口号 3000 node app.js var express = require(express); const path = require(path); const axios = require("axios"); const HttpsProxyAgent = require("https-proxy-agent"); var app = express(); app.set(port, 3000); app.get(/, function(req, res){ const httpsAgent = new HttpsProxyAgent(`http://127.0.0.1:4000`); const instance = axios.create({ proxy:false, httpsAgent }) instance(http://127.0.0.1:4000/) .then(function(res) { console.log(res); }) }); app.listen(app.get(port), function(){ console.log( Express started on http://localhost: + app.get(port) + ; press Ctrl-C to terminate. ); }); test.js 4000 node test.js var express = require(express); const path = require(path) var app = express(); app.set(port, 4000); app.get(/, function(req, res){ res.end(成功啦); }); app.listen(app.get(port), function(){ console.log( Express started on http://localhost: + app.get(port) + ; press Ctrl-C to terminate. ); }); 结果
经验分享 程序员 微信小程序 职场和发展