mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 19:48:50 +03:00
Extracted version-match
middleware to separate package
- this middlware is standalone and has 100% test coverage, therefore we can move it out to a separate package and remap the requires accordingly
This commit is contained in:
parent
025ebb7890
commit
93e0898c12
@ -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'));
|
||||
|
@ -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')
|
||||
};
|
||||
|
@ -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",
|
||||
|
6
ghost/mw-version-match/.eslintrc.js
Normal file
6
ghost/mw-version-match/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/node'
|
||||
]
|
||||
};
|
23
ghost/mw-version-match/README.md
Normal file
23
ghost/mw-version-match/README.md
Normal file
@ -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
|
||||
|
1
ghost/mw-version-match/index.js
Normal file
1
ghost/mw-version-match/index.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./lib/mw-version-match');
|
30
ghost/mw-version-match/package.json
Normal file
30
ghost/mw-version-match/package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
6
ghost/mw-version-match/test/.eslintrc.js
Normal file
6
ghost/mw-version-match/test/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/test'
|
||||
]
|
||||
};
|
@ -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;
|
Loading…
Reference in New Issue
Block a user