mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Merge pull request #5899 from ErisDS/theme-lookup
Remove unnecessary API lookup for activeTheme
This commit is contained in:
commit
f7015600b8
2 changed files with 11 additions and 16 deletions
|
@ -1,7 +1,6 @@
|
|||
var _ = require('lodash'),
|
||||
express = require('express'),
|
||||
path = require('path'),
|
||||
api = require('../api'),
|
||||
config = require('../config'),
|
||||
utils = require('../utils');
|
||||
|
||||
|
@ -12,11 +11,10 @@ function isBlackListedFileType(file) {
|
|||
}
|
||||
|
||||
function forwardToExpressStatic(req, res, next) {
|
||||
api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function then(response) {
|
||||
var activeTheme = response.settings[0];
|
||||
|
||||
express['static'](path.join(config.paths.themePath, activeTheme.value), {maxAge: utils.ONE_YEAR_MS})(req, res, next);
|
||||
});
|
||||
express['static'](
|
||||
path.join(config.paths.themePath, req.app.get('activeTheme')),
|
||||
{maxAge: utils.ONE_YEAR_MS}
|
||||
)(req, res, next);
|
||||
}
|
||||
|
||||
function staticTheme() {
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
/*jshint expr:true*/
|
||||
var sinon = require('sinon'),
|
||||
should = require('should'),
|
||||
Promise = require('bluebird'),
|
||||
|
||||
api = require('../../../server/api'),
|
||||
express = require('express'),
|
||||
staticTheme = require('../../../server/middleware/static-theme');
|
||||
|
||||
|
@ -46,23 +44,22 @@ describe('staticTheme', function () {
|
|||
|
||||
it('should call express.static if valid file type', function (done) {
|
||||
var req = {
|
||||
url: 'myvalidfile.css'
|
||||
url: 'myvalidfile.css',
|
||||
app: {
|
||||
get: function () { return 'casper'; }
|
||||
}
|
||||
},
|
||||
settingsStub,
|
||||
activeThemeStub,
|
||||
sandbox = sinon.sandbox.create(),
|
||||
expressStatic = sinon.spy(express, 'static');
|
||||
|
||||
settingsStub = sandbox.stub(api.settings, 'read').withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'activeKey',
|
||||
value: 'casper'
|
||||
}]
|
||||
}));
|
||||
activeThemeStub = sandbox.spy(req.app, 'get');
|
||||
|
||||
staticTheme(null)(req, null, function (reqArg, res, next2) {
|
||||
/*jshint unused:false */
|
||||
sandbox.restore();
|
||||
next.called.should.be.false;
|
||||
activeThemeStub.called.should.be.true;
|
||||
expressStatic.called.should.be.true;
|
||||
expressStatic.args[0][1].maxAge.should.exist;
|
||||
done();
|
||||
|
|
Loading…
Add table
Reference in a new issue