diff --git a/ghost/core/core/server/web/api/endpoints/admin/app.js b/ghost/core/core/server/web/api/endpoints/admin/app.js index 42b83e4d23..3ac02257f4 100644 --- a/ghost/core/core/server/web/api/endpoints/admin/app.js +++ b/ghost/core/core/server/web/api/endpoints/admin/app.js @@ -1,10 +1,11 @@ const debug = require('@tryghost/debug')('web:endpoints:admin:app'); const boolParser = require('express-query-boolean'); -const express = require('../../../../../shared/express'); const bodyParser = require('body-parser'); -const shared = require('../../../shared'); -const apiMw = require('../../middleware'); const errorHandler = require('@tryghost/mw-error-handler'); +const versionMatch = require('@tryghost/mw-version-match'); + +const shared = require('../../../shared'); +const express = require('../../../../../shared/express'); const sentry = require('../../../../../shared/sentry'); const routes = require('./routes'); const APIVersionCompatibilityService = require('../../../../services/api-version-compatibility'); @@ -24,7 +25,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(apiMw.versionMatch); + apiApp.use(versionMatch); // Admin API shouldn't be cached apiApp.use(shared.middleware.cacheControl('private')); diff --git a/ghost/core/core/server/web/api/middleware/index.js b/ghost/core/core/server/web/api/middleware/index.js index 91b438796c..a30445b446 100644 --- a/ghost/core/core/server/web/api/middleware/index.js +++ b/ghost/core/core/server/web/api/middleware/index.js @@ -1,6 +1,5 @@ module.exports = { cors: require('./cors'), updateUserLastSeen: require('./update-user-last-seen'), - upload: require('./upload'), - versionMatch: require('./version-match') + upload: require('./upload') }; diff --git a/ghost/core/package.json b/ghost/core/package.json index cad4b42683..5cf19c11ce 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -119,6 +119,7 @@ "@tryghost/mw-cache-control": "0.0.0", "@tryghost/mw-error-handler": "0.0.0", "@tryghost/mw-session-from-token": "0.0.0", + "@tryghost/mw-version-match": "0.0.0", "@tryghost/mw-vhost": "0.0.0", "@tryghost/nodemailer": "0.3.32", "@tryghost/nql": "0.11.0", diff --git a/ghost/mw-version-match/.eslintrc.js b/ghost/mw-version-match/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/mw-version-match/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/mw-version-match/README.md b/ghost/mw-version-match/README.md new file mode 100644 index 0000000000..20cfe72469 --- /dev/null +++ b/ghost/mw-version-match/README.md @@ -0,0 +1,23 @@ +# Mw Version Match + +Version compatibility middleware for Ghost + + +## Usage + + +## Develop + +This is a monorepo package. + +Follow the instructions for the top-level repo. +1. `git clone` this repo & `cd` into it as usual +2. Run `yarn` to install top-level dependencies. + + + +## Test + +- `yarn lint` run just eslint +- `yarn test` run lint and tests + diff --git a/ghost/mw-version-match/index.js b/ghost/mw-version-match/index.js new file mode 100644 index 0000000000..5ef8696c30 --- /dev/null +++ b/ghost/mw-version-match/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/mw-version-match'); diff --git a/ghost/core/core/server/web/api/middleware/version-match.js b/ghost/mw-version-match/lib/mw-version-match.js similarity index 100% rename from ghost/core/core/server/web/api/middleware/version-match.js rename to ghost/mw-version-match/lib/mw-version-match.js diff --git a/ghost/mw-version-match/package.json b/ghost/mw-version-match/package.json new file mode 100644 index 0000000000..4a5f9f87bd --- /dev/null +++ b/ghost/mw-version-match/package.json @@ -0,0 +1,30 @@ +{ + "name": "@tryghost/mw-version-match", + "version": "0.0.0", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/mw-version-match", + "author": "Ghost Foundation", + "private": true, + "main": "index.js", + "scripts": { + "dev": "echo \"Implement me!\"", + "test:unit": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'", + "test": "yarn test:unit", + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" + }, + "files": [ + "index.js", + "lib" + ], + "devDependencies": { + "c8": "7.13.0", + "mocha": "10.2.0", + "sinon": "15.0.1" + }, + "dependencies": { + "@tryghost/errors": "1.2.21", + "@tryghost/tpl": "0.1.21", + "semver": "7.3.8" + } +} diff --git a/ghost/mw-version-match/test/.eslintrc.js b/ghost/mw-version-match/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/mw-version-match/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/core/test/unit/server/web/api/middleware/version-match.test.js b/ghost/mw-version-match/test/version-match.test.js similarity index 96% rename from ghost/core/test/unit/server/web/api/middleware/version-match.test.js rename to ghost/mw-version-match/test/version-match.test.js index e2fb5a04c5..fd76e00145 100644 --- a/ghost/core/test/unit/server/web/api/middleware/version-match.test.js +++ b/ghost/mw-version-match/test/version-match.test.js @@ -1,6 +1,7 @@ -const should = require('should'); +require('should'); const sinon = require('sinon'); -const versionMatch = require('../../../../../../core/server/web/api/middleware/version-match'); + +const versionMatch = require('../'); describe('Version Mismatch', function () { let req;