Created
September 6, 2014 12:38
-
-
Save johndstein/b04f44957c5c5cb4afba to your computer and use it in GitHub Desktop.
Node Request SSL Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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