Skip to content

Instantly share code, notes, and snippets.

@johndstein
Created September 6, 2014 12:38
Show Gist options
  • Save johndstein/b04f44957c5c5cb4afba to your computer and use it in GitHub Desktop.
Save johndstein/b04f44957c5c5cb4afba to your computer and use it in GitHub Desktop.
Node Request SSL Example
var Promise = require('bluebird');
var request = require('request');
var https = require('https');
var config = require('config');
var fs = require('fs');
function _readFileSafe(path) {
try {
return fs.readFileSync(path);
} catch (err) {
return null;
}
}
if (!key || ! cert) {
var key = _readFileSafe(config.baleen.key);
var cert = _readFileSafe(config.baleen.cert);
}
var agent = new https.Agent({
host: config.baleen.shadow.host,
port: config.baleen.shadow.port,
key: key,
cert: cert,
rejectUnauthorized: false
});
function isKnownBad(md5, cb) {
var body = JSON.stringify({
files: [md5]
});
var opts = {
method: 'POST',
body: body,
json: true,
agent: agent,
headers: {
'api-key': config.baleen.apikey
},
url: 'https://' + config.baleen.shadow.host + ':' + config.baleen.shadow.port + '/foo/bar'
};
request(opts, cb);
}
module.exports = {
isKnownBad: isKnownBad,
isKnownBadAsync: Promise.promisify(isKnownBad)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment