mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs #9178 - avoid importing 4 modules (logging, errors, events and i18n) - simply require common in each file
25 lines
851 B
JavaScript
25 lines
851 B
JavaScript
var semver = require('semver'),
|
|
common = require('../../../lib/common');
|
|
|
|
function checkVersionMatch(req, res, next) {
|
|
var clientVersion = req.get('X-Ghost-Version'),
|
|
serverVersion = res.locals.version,
|
|
constraint = '^' + clientVersion + '.0';
|
|
|
|
// no error when client is on an earlier minor version than server
|
|
// error when client is on a later minor version than server
|
|
// always error when the major version is different
|
|
|
|
if (clientVersion && !semver.satisfies(serverVersion, constraint)) {
|
|
return next(new common.errors.VersionMismatchError({
|
|
message: common.i18n.t('errors.middleware.api.versionMismatch', {
|
|
clientVersion: clientVersion,
|
|
serverVersion: serverVersion
|
|
})
|
|
}));
|
|
}
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = checkVersionMatch;
|