1
我正在研究axios以便在corp防火牆內部使用某些node.js http調用API--並且我在第一個障礙中倒下了。不能讓服務器端的axios api在防火牆後面調用
我發現,使用愛可信做以下
const axios = require('axios');
const API = 'https://jsonplaceholder.typicode.com';
/* GET api listing. */
router.get('/', (req, res) => {
res.send('api works');
});
// Get all posts
router.get('/posts', (req, res) => {
// Get posts from the mock api
axios.get(`${API}/posts`, { proxy: { host: 'http://proxy.com', port: 8080}})
//axios.get(`${API}/posts`)
.then(posts => {
res.status(200).json(posts.data);
})
.catch(error => {
res.status(500).send(error)
});
});
module.exports = router;
服務器HTTP調用一個例子,但,當我在防火牆後面,我得到以下
// http://localhost:3000/api/posts
錯誤{
「code」:「ENOTFOUND」,
「errno」:「ENOTFOUND」,
「系統調用」: 「的getaddrinfo」
「主機名」: 「http://proxy.com」
「宿主」: 「http://proxy.com」
「端口」:8080,
「配置」:{ 「transformRequest」:{}, "transformResponse": { }, "timeout": 0, "xsrfCookieName": "XSRF-TOKEN", "xsrfHeaderName": "X-XSRF-TOKEN", "maxContentLength": -1, "headers": { "Accept": "application/json, text/plain, */*", "User-Agent": "axios/0.15.3", "host": "jsonplaceholder.typicode.com" }, "method": "get", "proxy": { "host": "http://proxy.com", "port": 8080 }, "url": "https://jsonplaceholder.typicode.com/posts"
它工作時,我切換到直接連接到互聯網,代理設置是什麼我用NPM發現 - 我不知道最終的解決方案將是內部或防火牆外部但我不知道要做這個具體到這個api甚至glob盟友只是用於開發..任何幫助將不勝感激..