2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Attached api version to res.locals context

refs #9866

- each request get's the ghost api version attached
- this makes it possible to access the version in all steps (routing, theme helpers)
This commit is contained in:
kirrg001 2018-10-17 09:23:57 +02:00 committed by Katharina Irrgang
parent 1f55c90037
commit 987e41e8d6
2 changed files with 19 additions and 6 deletions

View file

@ -1,4 +1,5 @@
const ghostVersion = require('../../../lib/ghost-version');
const themeService = require('../../../services/themes');
// ### GhostLocals Middleware
// Expose the standard locals that every request will need to have available
@ -11,6 +12,8 @@ module.exports = function ghostLocals(req, res, next) {
res.locals.safeVersion = ghostVersion.safe;
// relative path from the URL
res.locals.relativeUrl = req.path;
// make ghost api version available for the theme + routing
res.locals.apiVersion = themeService.getActive().engine('ghost-api');
next();
};

View file

@ -1,16 +1,24 @@
var should = require('should'),
sinon = require('sinon'),
ghostLocals = require('../../../../server/web/shared/middlewares/ghost-locals'),
sandbox = sinon.sandbox.create();
const should = require('should');
const sinon = require('sinon');
const ghostLocals = require('../../../../server/web/shared/middlewares/ghost-locals');
const themeService = require('../../../../server/services/themes');
const sandbox = sinon.sandbox.create();
describe('Theme Handler', function () {
var req, res, next;
let req, res, next;
beforeEach(function () {
req = sandbox.spy();
res = sandbox.spy();
next = sandbox.spy();
sandbox.stub(themeService, 'getActive').callsFake(() => {
return {
engine() {
return 'v0.1';
}
};
});
});
afterEach(function () {
@ -26,7 +34,9 @@ describe('Theme Handler', function () {
res.locals.should.be.an.Object();
should.exist(res.locals.version);
should.exist(res.locals.safeVersion);
should.exist(res.locals.apiVersion);
res.locals.relativeUrl.should.equal(req.path);
res.locals.apiVersion.should.equal('v0.1');
next.called.should.be.true();
});
});