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:
parent
1f55c90037
commit
987e41e8d6
2 changed files with 19 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
const ghostVersion = require('../../../lib/ghost-version');
|
const ghostVersion = require('../../../lib/ghost-version');
|
||||||
|
const themeService = require('../../../services/themes');
|
||||||
|
|
||||||
// ### GhostLocals Middleware
|
// ### GhostLocals Middleware
|
||||||
// Expose the standard locals that every request will need to have available
|
// 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;
|
res.locals.safeVersion = ghostVersion.safe;
|
||||||
// relative path from the URL
|
// relative path from the URL
|
||||||
res.locals.relativeUrl = req.path;
|
res.locals.relativeUrl = req.path;
|
||||||
|
// make ghost api version available for the theme + routing
|
||||||
|
res.locals.apiVersion = themeService.getActive().engine('ghost-api');
|
||||||
|
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
var should = require('should'),
|
const should = require('should');
|
||||||
sinon = require('sinon'),
|
const sinon = require('sinon');
|
||||||
ghostLocals = require('../../../../server/web/shared/middlewares/ghost-locals'),
|
const ghostLocals = require('../../../../server/web/shared/middlewares/ghost-locals');
|
||||||
|
const themeService = require('../../../../server/services/themes');
|
||||||
sandbox = sinon.sandbox.create();
|
const sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
describe('Theme Handler', function () {
|
describe('Theme Handler', function () {
|
||||||
var req, res, next;
|
let req, res, next;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
req = sandbox.spy();
|
req = sandbox.spy();
|
||||||
res = sandbox.spy();
|
res = sandbox.spy();
|
||||||
next = sandbox.spy();
|
next = sandbox.spy();
|
||||||
|
|
||||||
|
sandbox.stub(themeService, 'getActive').callsFake(() => {
|
||||||
|
return {
|
||||||
|
engine() {
|
||||||
|
return 'v0.1';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
@ -26,7 +34,9 @@ describe('Theme Handler', function () {
|
||||||
res.locals.should.be.an.Object();
|
res.locals.should.be.an.Object();
|
||||||
should.exist(res.locals.version);
|
should.exist(res.locals.version);
|
||||||
should.exist(res.locals.safeVersion);
|
should.exist(res.locals.safeVersion);
|
||||||
|
should.exist(res.locals.apiVersion);
|
||||||
res.locals.relativeUrl.should.equal(req.path);
|
res.locals.relativeUrl.should.equal(req.path);
|
||||||
|
res.locals.apiVersion.should.equal('v0.1');
|
||||||
next.called.should.be.true();
|
next.called.should.be.true();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue