diff --git a/lib/expressapp.js b/lib/expressapp.js index 3ad7b2d..df8268d 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -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(); }); diff --git a/lib/server.js b/lib/server.js index 1062171..8a88323 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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; }; diff --git a/test/expressapp.js b/test/expressapp.js index 2a9e8b0..cbf8671 100644 --- a/test/expressapp.js +++ b/test/expressapp.js @@ -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', diff --git a/test/integration/server.js b/test/integration/server.js index 2bfa182..de82df0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -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); }); });