Last week I was working with the team which their dev machines were behind the NTLM proxy! All the API calls from node js app were failing! Below is how we solved the proxy problem.
1. Install Fiddler https://www.telerik.com/download/fiddler
Make sure it is installed somewhere that you can run the application like C:\dev
2. Once installed, open and click 'Rules' in the top menu bar and click 'Automatically authenticate'
3. Configure proxy. From a command prompt set your proxy to point to Fiddler:
```
setx HTTP_PROXY http://localhost:8888
setx HTTPS_PROXY http://localhost:8888
```
Node js and proxy
npm config edit --global
proxy=http://proxyIP:Port/
https-proxy=http://proxyIP:Port/
strict-ssl=false
or run this following command lines
npm config set proxy http://proxyIP:Port/
npm config set https-proxy http://proxyIP:Port/
How to set proxy in request-promise module
Set the proxy property of the object you are passing to `request-promise`
```typescript
import * as rp from "request-promise";
const uri = "australiaeast.api.cognitive.microsoft.com";
const path = "/text/analytics/v2.0/keyPhrases";
const options = {
body: {},
headers: {},
json: true, // Automatically stringifies the body to JSON
method: "POST",
proxy: isdevenvironment ? http://proxyIP:Port/: undefined,
uri: `https://${uri}${path}`,
};
const parsedBody = await rp(options);
```
How to set proxy to use app insights
Set proxyHttpUrl and proxyHttpsUrl properties on the client's config property.
```typescript
import * as appInsights from "applicationinsights";
appInsights.setup(appInsightsKey)
.setAutoDependencyCorrelation(true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setUseDiskRetryCaching(true)
.start();
let telemetry = appInsights.defaultClient;
if (isdevenvironment) {
telemetry.config.proxyHttpUrl = yourproxy
}
if (isdevenvironment) {
telemetry.config.proxyHttpsUrl = yourproxy
}
```
Comments