mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
20f4166cc5
refs #6949 - Adds a new VersionMismatchError with status 400 (bad request) - Adds middleware that checks the X-Ghost-Version header if it is provided - If it is not provided, the middleware does nothing - If it is provided, and the versions match, the middleware does nothing - If it is provided, and the versions don't match, the middleware returns a VersionMismatchError - Includes both unit and a functional test to prove the middleware works alone and as part of the whole system
21 lines
579 B
JavaScript
21 lines
579 B
JavaScript
var errors = require('../../errors'),
|
|
i18n = require('../../i18n');
|
|
|
|
function checkVersionMatch(req, res, next) {
|
|
var requestVersion = req.get('X-Ghost-Version'),
|
|
currentVersion = res.locals.safeVersion;
|
|
|
|
if (requestVersion && requestVersion !== currentVersion) {
|
|
return next(new errors.VersionMismatchError(
|
|
i18n.t(
|
|
'errors.middleware.api.versionMismatch',
|
|
{requestVersion: requestVersion, currentVersion: currentVersion}
|
|
)
|
|
));
|
|
}
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = checkVersionMatch;
|