add x-service-version header
This commit is contained in:
parent
70f83f545c
commit
19da3f8fd5
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue