mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs #9178 - move express apps to one place (called `web`) - requires https://github.com/TryGhost/Ghost-Admin/pull/923 - any further improvements are not part of this PR - this PR just moves the files and ensures the paths are up-to-date
23 lines
824 B
JavaScript
23 lines
824 B
JavaScript
var semver = require('semver'),
|
|
errors = require('../../../errors'),
|
|
i18n = require('../../../i18n');
|
|
|
|
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 errors.VersionMismatchError({
|
|
message: i18n.t('errors.middleware.api.versionMismatch', {clientVersion: clientVersion, serverVersion: serverVersion})
|
|
}));
|
|
}
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = checkVersionMatch;
|