Moved version-match mw into api app

- Moved version-match from shared to api as it is not shared (except within the API)
- This file is only used in one part of the app, this updates the code structure to reflect this
- This is one of many similar changes needed to make it easier to refactor to the existing setup
This commit is contained in:
Hannah Wolfe 2020-04-22 06:26:13 +01:00
parent adde1fa01c
commit 41c3b4e92b
6 changed files with 9 additions and 8 deletions

View File

@ -3,6 +3,7 @@ const boolParser = require('express-query-boolean');
const express = require('express');
const bodyParser = require('body-parser');
const shared = require('../../../shared');
const mw = require('../../middleware');
const routes = require('./routes');
const sentry = require('../../../../sentry');
@ -25,7 +26,7 @@ module.exports = function setupApiApp() {
// Check version matches for API requests, depends on res.locals.safeVersion being set
// Therefore must come after themeHandler.ghostLocals, for now
apiApp.use(shared.middlewares.api.versionMatch);
apiApp.use(mw.versionMatch);
// Admin API shouldn't be cached
apiApp.use(shared.middlewares.cacheControl('private'));

View File

@ -0,0 +1,3 @@
module.exports = {
versionMatch: require('./version-match')
};

View File

@ -1,6 +1,6 @@
const semver = require('semver');
const errors = require('@tryghost/errors');
const {i18n} = require('../../../../lib/common');
const {i18n} = require('../../../lib/common');
function checkVersionMatch(req, res, next) {
const clientVersion = req.get('X-Ghost-Version');

View File

@ -3,6 +3,7 @@ const boolParser = require('express-query-boolean');
const express = require('express');
const bodyParser = require('body-parser');
const shared = require('../../../shared');
const mw = require('../../middleware');
const routes = require('./routes');
const sentry = require('../../../../sentry');
@ -25,7 +26,7 @@ module.exports = function setupApiApp() {
// Check version matches for API requests, depends on res.locals.safeVersion being set
// Therefore must come after themeHandler.ghostLocals, for now
apiApp.use(shared.middlewares.api.versionMatch);
apiApp.use(mw.versionMatch);
// Admin API shouldn't be cached
apiApp.use(shared.middlewares.cacheControl('private'));

View File

@ -5,9 +5,5 @@ module.exports = {
get spamPrevention() {
return require('./spam-prevention');
},
get versionMatch() {
return require('./version-match');
}
};

View File

@ -1,6 +1,6 @@
var should = require('should'),
sinon = require('sinon'),
versionMatch = require('../../../../../core/server/web/shared/middlewares/api/version-match');
versionMatch = require('../../../../../core/server/web/api/middleware/version-match');
describe('Version Mismatch', function () {
var req, res, getStub, nextStub;