fix(fingerprint): check for getPeerCertificate fn existence added
This commit is contained in:
parent
c2bfa215c0
commit
443a481487
1 changed files with 13 additions and 8 deletions
|
|
@ -18,13 +18,13 @@ Error.prototype.toJSON = function () {
|
|||
return ret;
|
||||
};
|
||||
|
||||
var poll = function(req, res) {
|
||||
function poll(req, res) {
|
||||
var rateRec = _trader.rate();
|
||||
var balanceRec = _trader.balance;
|
||||
var fingerprint = getFingerprint(req);
|
||||
|
||||
logger.debug('poll request from: %s', fingerprint);
|
||||
|
||||
|
||||
// `rateRec` and `balanceRec` are both objects, so there's no danger
|
||||
// of misinterpreting rate or balance === 0 as 'Server initializing'.
|
||||
if (!rateRec || !balanceRec) {
|
||||
|
|
@ -54,13 +54,13 @@ var poll = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
var trade = function (req, res) {
|
||||
function trade(req, res) {
|
||||
var fingerprint = getFingerprint(req);
|
||||
_trader.trade(req.body, fingerprint);
|
||||
res.json({err: null});
|
||||
};
|
||||
|
||||
var send = function(req, res) {
|
||||
function send(req, res) {
|
||||
var fingerprint = getFingerprint(req);
|
||||
_trader.sendBitcoins(fingerprint, req.body, function(err, txHash) {
|
||||
res.json({
|
||||
|
|
@ -71,7 +71,7 @@ var send = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
var pair = function(req, res) {
|
||||
function pair(req, res) {
|
||||
var token = req.body.token;
|
||||
var name = req.body.name;
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ var pair = function(req, res) {
|
|||
);
|
||||
};
|
||||
|
||||
exports.init = function(app, config, trader, authMiddleware) {
|
||||
function init(app, config, trader, authMiddleware) {
|
||||
_lamassuConfig = config;
|
||||
_trader = trader;
|
||||
|
||||
|
|
@ -102,6 +102,11 @@ exports.init = function(app, config, trader, authMiddleware) {
|
|||
};
|
||||
|
||||
function getFingerprint(req) {
|
||||
return req.connection.getPeerCertificate &&
|
||||
return typeof req.connection.getPeerCertificate === 'function' &&
|
||||
req.connection.getPeerCertificate().fingerprint;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
getFingerprint: getFingerprint
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue