Browse Source

Added support for proxy agent

pull/14/head
Erik Günther 11 years ago
parent
commit
e1a5b09874
3 changed files with 33 additions and 3 deletions
  1. +26
    -0
      README.md
  2. +5
    -2
      lib/client.js
  3. +2
    -1
      package.json

+ 26
- 0
README.md View File

@ -41,6 +41,32 @@ var options = {
dogapi.initialize(options); dogapi.initialize(options);
``` ```
### HTTPS Proxy
If you are behind a proxy you need to a proxy agent. You can use the https proxy agent from
http://blog.vanamco.com/connecting-via-proxy-node-js/ if you like.
To configure dogapi with the agent just add it to the options.
```javascript
var dogapi = require("dogapi");
//Code from http://blog.vanamco.com/connecting-via-proxy-node-js/
var HttpsProxyAgent = require("./httpsproxyagent");
var agent = new HttpsProxyAgent({
proxyHost: "MY_PROXY_HOST",
proxyPort: 3128
});
var options = {
api_key: "YOUR_KEY_HERE",
app_key: "YOUR_KEY_HERE",
proxy_agent: agent
};
dogapi.initialize(options);
```
## CLI Usage ## CLI Usage
`dogapi` now ships with a command line interface `dogapi`. To use it you `dogapi` now ships with a command line interface `dogapi`. To use it you


+ 5
- 2
lib/client.js View File

@ -3,7 +3,6 @@ var https = require("https");
var url = require("url"); var url = require("url");
var util = require("util"); var util = require("util");
/*section: client /*section: client
*comment: | *comment: |
* the constructor for _client_ object * the constructor for _client_ object
@ -14,6 +13,7 @@ var util = require("util");
var client = function(){ var client = function(){
this.api_key = null; this.api_key = null;
this.app_key = null; this.app_key = null;
this.proxy_agent = null;
this.api_version = "v1"; this.api_version = "v1";
this.api_host = "app.datadoghq.com"; this.api_host = "app.datadoghq.com";
}; };
@ -69,9 +69,12 @@ client.prototype.request = function(method, path, params, callback){
hostname: this.api_host, hostname: this.api_host,
port: 443, port: 443,
method: method.toUpperCase(), method: method.toUpperCase(),
path: path,
path: path
}; };
if(this.proxy_agent)
http_options["agent"] = this.proxy_agent;
if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){ if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){
http_options["headers"] = { http_options["headers"] = {
"Content-Type": "application/json", "Content-Type": "application/json",


+ 2
- 1
package.json View File

@ -33,7 +33,8 @@
"dependencies": { "dependencies": {
"extend": "^2.0.0", "extend": "^2.0.0",
"minimist": "^1.1.1", "minimist": "^1.1.1",
"rc": "^1.0.0"
"rc": "^1.0.0",
"tls": "0.0.1"
}, },
"devDependencies": { "devDependencies": {
"docast": "^0.1.1", "docast": "^0.1.1",


Loading…
Cancel
Save