В Corporate Proxy я устанавливаю настройки конфигурации npm. Это работает.
npm config set https_proxy=http://username:password@proxy.example.com:8080
npm config set http_proxy=http://username:password@proxy.example.com:8080
npm config set proxy=http://username:password@proxy.example.com:8080
В Node.JS я использовал модуль request
для вызова HTTP-запроса. Это не работает. Я получаю следующую ошибку.
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: 3646 == 0
at ClientRequest.onConnect (C:\Users\Username\Documents\Workspace\node-course\web-server\node_modules\tunnel-agent\index.js:160:14)
at Object.onceWrapper (events.js:284:20)
at ClientRequest.emit (events.js:196:13)
at Socket.socketOnData (_http_client.js:492:11)
at Socket.emit (events.js:196:13)
at addChunk (_stream_readable.js:290:12)
at readableAddChunk (_stream_readable.js:271:11)
at Socket.Readable.push (_stream_readable.js:226:10)
at TCP.onStreamRead (internal/stream_base_commons.js:166:17)
[nodemon] app crashed - waiting for file changes before starting...
Мой код
const url = 'https://jsonplaceholder.typicode.com/posts';
request({ url, json: true }, (error, { body } = {}) => {
console.log(error, body);
})
URL-адрес прокси, который я добавил в NPM с помощью npm config set ...
Не работает.
Затем на основе npm request
документации (https://github.com/request/request#controlling-proxy-behaviour-using-environment-variables) Я добавил переменную среды в Windows Machine с помощью (https://docs.cloudfoundry.org/cf-cli/http-proxy.html). Это также не работает.