Merge pull request #385 from isocolsky/feat/version-in-header

Add service version to header for all requests
This commit is contained in:
Matias Alejo Garcia 2015-10-19 11:42:03 -03:00
commit f5cb854b9a
4 changed files with 22 additions and 10 deletions

View File

@ -34,6 +34,7 @@ ExpressApp.prototype.start = function(opts, cb) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'x-signature,x-identity,x-client-version,X-Requested-With,Content-Type,Authorization');
res.setHeader('x-service-version', WalletService.getServiceVersion());
next();
});
var allowCORS = function(req, res, next) {
@ -430,9 +431,8 @@ ExpressApp.prototype.start = function(opts, cb) {
});
router.get('/v1/version/', function(req, res) {
var server = getServer(req, res);
res.json({
serviceVersion: server.serviceVersion
serviceVersion: WalletService.getServiceVersion(),
});
res.end();
});

View File

@ -15,7 +15,6 @@ var Address = Bitcore.Address;
var ClientError = require('./errors/clienterror');
var Errors = require('./errors/errordefinitions');
var Package = require('../package');
var Utils = require('./utils');
var Lock = require('./lock');
@ -33,6 +32,7 @@ var storage;
var blockchainExplorer;
var blockchainExplorerOpts;
var messageBroker;
var serviceVersion;
var MAX_KEYS = 100;
@ -50,7 +50,12 @@ function WalletService() {
this.blockchainExplorerOpts = blockchainExplorerOpts;
this.messageBroker = messageBroker;
this.notifyTicker = 0;
this.serviceVersion = 'bws-' + Package.version;
};
WalletService.getServiceVersion = function() {
if (!serviceVersion)
serviceVersion = 'bws-' + require('../package').version;
return serviceVersion;
};

View File

@ -57,7 +57,7 @@ describe('ExpressApp', function() {
it('/v2/wallets', function(done) {
var server = {
getStatus: sinon.stub().callsArgWith(1, null, {})
getStatus: sinon.stub().callsArgWith(1, null, {}),
};
var TestExpressApp = proxyquire('../lib/expressapp', {
'./server': {
@ -73,9 +73,11 @@ describe('ExpressApp', function() {
'x-signature': 'signature'
}
};
request(requestOptions, function(err, response, body) {
request(requestOptions, function(err, res, body) {
should.not.exist(err);
response.statusCode.should.equal(200);
should.exist(res.headers['x-service-version']);
res.headers['x-service-version'].should.equal('bws-' + require('../package').version);
res.statusCode.should.equal(200);
body.should.equal('{}');
done();
});
@ -102,9 +104,9 @@ describe('ExpressApp', function() {
'x-signature': 'signature'
}
};
request(requestOptions, function(err, response, body) {
request(requestOptions, function(err, res, body) {
should.not.exist(err);
response.statusCode.should.equal(200);
res.statusCode.should.equal(200);
body.should.equal('{}');
server.getNotifications.calledWith({
notificationId: '123',

View File

@ -813,13 +813,18 @@ describe('Wallet service', function() {
});
describe('#getServiceVersion', function() {
it('should get version from package', function() {
WalletService.getServiceVersion().should.equal('bws-' + require('../../package').version);
});
});
describe('#getInstance', function() {
it('should get server instance', function() {
var server = WalletService.getInstance({
clientVersion: 'bwc-0.0.1',
});
server.clientVersion.should.equal('bwc-0.0.1');
server.serviceVersion.indexOf('bws-').should.equal(0);
});
});