From 42e722d627a11f0671521f9b1cd93103918c84b3 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 11 Aug 2022 14:10:39 +0200 Subject: [PATCH] Moved Cache-Control middleware to separate package refs https://github.com/TryGhost/Toolbox/issues/363 - this middleware is standalone and I suspect we're going to be touching it further when we work on Ghost's caching in the near future --- .../server/web/shared/middleware/index.js | 2 +- ghost/core/package.json | 1 + ghost/mw-cache-control/.eslintrc.js | 6 ++++ ghost/mw-cache-control/README.md | 23 +++++++++++++++ ghost/mw-cache-control/index.js | 1 + .../lib/mw-cache-control.js} | 0 ghost/mw-cache-control/package.json | 28 +++++++++++++++++++ ghost/mw-cache-control/test/.eslintrc.js | 6 ++++ .../test}/cache-control.test.js | 5 ++-- 9 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 ghost/mw-cache-control/.eslintrc.js create mode 100644 ghost/mw-cache-control/README.md create mode 100644 ghost/mw-cache-control/index.js rename ghost/{core/core/server/web/shared/middleware/cache-control.js => mw-cache-control/lib/mw-cache-control.js} (100%) create mode 100644 ghost/mw-cache-control/package.json create mode 100644 ghost/mw-cache-control/test/.eslintrc.js rename ghost/{core/test/unit/server/web/shared/middleware => mw-cache-control/test}/cache-control.test.js (95%) diff --git a/ghost/core/core/server/web/shared/middleware/index.js b/ghost/core/core/server/web/shared/middleware/index.js index 4c8faf4438..b6d6aa8afc 100644 --- a/ghost/core/core/server/web/shared/middleware/index.js +++ b/ghost/core/core/server/web/shared/middleware/index.js @@ -8,7 +8,7 @@ module.exports = { }, get cacheControl() { - return require('./cache-control'); + return require('@tryghost/mw-cache-control'); }, get prettyUrls() { diff --git a/ghost/core/package.json b/ghost/core/package.json index ccaa2a47bf..13d5871deb 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -92,6 +92,7 @@ "@tryghost/metrics": "1.0.15", "@tryghost/minifier": "0.0.0", "@tryghost/mw-api-version-mismatch": "0.0.0", + "@tryghost/mw-cache-control": "0.0.0", "@tryghost/mw-error-handler": "0.0.0", "@tryghost/mw-session-from-token": "0.0.0", "@tryghost/mw-vhost": "0.0.0", diff --git a/ghost/mw-cache-control/.eslintrc.js b/ghost/mw-cache-control/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/mw-cache-control/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/mw-cache-control/README.md b/ghost/mw-cache-control/README.md new file mode 100644 index 0000000000..8909d5bbfc --- /dev/null +++ b/ghost/mw-cache-control/README.md @@ -0,0 +1,23 @@ +# Mw Cache Control + +Cache-Control 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-cache-control/index.js b/ghost/mw-cache-control/index.js new file mode 100644 index 0000000000..c75f6120c5 --- /dev/null +++ b/ghost/mw-cache-control/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/mw-cache-control'); diff --git a/ghost/core/core/server/web/shared/middleware/cache-control.js b/ghost/mw-cache-control/lib/mw-cache-control.js similarity index 100% rename from ghost/core/core/server/web/shared/middleware/cache-control.js rename to ghost/mw-cache-control/lib/mw-cache-control.js diff --git a/ghost/mw-cache-control/package.json b/ghost/mw-cache-control/package.json new file mode 100644 index 0000000000..919c057f71 --- /dev/null +++ b/ghost/mw-cache-control/package.json @@ -0,0 +1,28 @@ +{ + "name": "@tryghost/mw-cache-control", + "version": "0.0.0", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/mw-cache-control", + "author": "Ghost Foundation", + "private": true, + "main": "index.js", + "scripts": { + "dev": "echo \"Implement me!\"", + "test": "NODE_ENV=testing c8 --all --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'", + "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.12.0", + "mocha": "10.0.0", + "should": "13.2.3", + "sinon": "14.0.0" + }, + "dependencies": { + "lodash": "4.17.21" + } +} diff --git a/ghost/mw-cache-control/test/.eslintrc.js b/ghost/mw-cache-control/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/mw-cache-control/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/core/test/unit/server/web/shared/middleware/cache-control.test.js b/ghost/mw-cache-control/test/cache-control.test.js similarity index 95% rename from ghost/core/test/unit/server/web/shared/middleware/cache-control.test.js rename to ghost/mw-cache-control/test/cache-control.test.js index 6563b235e6..bafc680f31 100644 --- a/ghost/core/test/unit/server/web/shared/middleware/cache-control.test.js +++ b/ghost/mw-cache-control/test/cache-control.test.js @@ -1,8 +1,9 @@ const should = require('should'); const sinon = require('sinon'); -const cacheControl = require('../../../../../../core/server/web/shared/middleware/cache-control'); -describe('Middleware: cacheControl', function () { +const cacheControl = require('../'); + +describe('Cache-Control middleware', function () { let res; beforeEach(function () {