Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 馃拕 Combine slashes & uncapitalise middleware - these bits of middleware belong together - ideally they should be optimised * 馃帹 Move ghostLocals out of themeHandler GhostLocals sets several important values which are needed for every part of the application, admin, api and theme. Therefore, it doesn't make sense for it to be bundled in the themeHandler. * 馃悰 Fix the uncapitalise middleware - Updated to make correct use of req.baseUrl, req.path, req.url & req.originalUrl - Updated the tests to actually cover our weird cases * 馃帹 Move ghostVersion logic out of config * 馃拕 Group static / asset-related middleware together * 馃敟 Remove /shared/ asset handling - The 5 files which are located in `/shared/` are all handled by individual calls to `serveSharedFile` - Therefore this code is redundant
- Loading branch information
Showing
13 changed files
with
275 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var ghostVersion = require('../utils/ghost-version'); | ||
|
||
// ### GhostLocals Middleware | ||
// Expose the standard locals that every request will need to have available | ||
module.exports = function ghostLocals(req, res, next) { | ||
// Make sure we have a locals value. | ||
res.locals = res.locals || {}; | ||
// The current Ghost version | ||
res.locals.version = ghostVersion.full; | ||
// The current Ghost version, but only major.minor | ||
res.locals.safeVersion = ghostVersion.safe; | ||
// relative path from the URL | ||
res.locals.relativeUrl = req.path; | ||
|
||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Pretty URL redirects | ||
// | ||
// These are two pieces of middleware that handle ensuring that | ||
// URLs get formatted correctly. | ||
// Slashes ensures that we get trailing slashes | ||
// Uncapitalise changes case to lowercase | ||
// @TODO optimise this to reduce the number of redirects required to get to a pretty URL | ||
// @TODO move this to being used by routers? | ||
var slashes = require('connect-slashes'), | ||
utils = require('../utils'); | ||
|
||
module.exports = [ | ||
slashes(true, { | ||
headers: { | ||
'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S | ||
} | ||
}), | ||
require('./uncapitalise') | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var packageInfo = require('../../../package.json'), | ||
version = packageInfo.version; | ||
|
||
module.exports = { | ||
full: version, | ||
safe: version.match(/^(\d+\.)?(\d+)/)[0] | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var sinon = require('sinon'), | ||
should = require('should'), | ||
ghostLocals = require('../../../server/middleware/ghost-locals'); | ||
|
||
describe('Theme Handler', function () { | ||
var req, res, next; | ||
|
||
beforeEach(function () { | ||
req = sinon.spy(); | ||
res = sinon.spy(); | ||
next = sinon.spy(); | ||
}); | ||
|
||
describe('ghostLocals', function () { | ||
it('sets all locals', function () { | ||
req.path = '/awesome-post'; | ||
|
||
ghostLocals(req, res, next); | ||
|
||
res.locals.should.be.an.Object(); | ||
should.exist(res.locals.version); | ||
should.exist(res.locals.safeVersion); | ||
res.locals.relativeUrl.should.equal(req.path); | ||
next.called.should.be.true(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.