Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit b32979a

Browse files
authored
Merge pull request #40 from patrixr/new-admin-endpoints
New admin endpoints
2 parents 81f2ced + 83000bd commit b32979a

File tree

4 files changed

+154
-15
lines changed

4 files changed

+154
-15
lines changed

lib/index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Router = require('koa-router');
33
const crypto = require('crypto');
44
const _ = require('lodash');
55
const pluralize = require('pluralize');
6+
const semver = require('semver');
67

78
const PLUGIN_NAME = 'cache';
89

@@ -319,11 +320,21 @@ const Cache = (strapi) => {
319320
}
320321
};
321322

322-
router.post('/content-manager/explorer/:scope', bustAdmin);
323-
router.post('/content-manager/explorer/:scope/publish/:id*', bustAdmin);
324-
router.post('/content-manager/explorer/:scope/unpublish/:id*', bustAdmin);
325-
router.put('/content-manager/explorer/:scope/:id*', bustAdmin);
326-
router.delete('/content-manager/explorer/:scope/:id*', bustAdmin);
323+
if (semver.lt(process.version, '3.4.0')) {
324+
router.post('/content-manager/explorer/:scope', bustAdmin);
325+
router.post('/content-manager/explorer/:scope/publish/:id*', bustAdmin);
326+
router.post('/content-manager/explorer/:scope/unpublish/:id*', bustAdmin);
327+
router.put('/content-manager/explorer/:scope/:id*', bustAdmin);
328+
router.delete('/content-manager/explorer/:scope/:id*', bustAdmin);
329+
} else {
330+
['collection-types', 'single-types'].forEach(type => {
331+
router.post(`/content-manager/${type}/:scope`, bustAdmin);
332+
router.post(`/content-manager/${type}/:scope/publish/:id*`, bustAdmin);
333+
router.post(`/content-manager/${type}/:scope/unpublish/:id*`, bustAdmin);
334+
router.put(`/content-manager/${type}/:scope/:id*`, bustAdmin);
335+
router.delete(`/content-manager/${type}/:scope/:id*`, bustAdmin);
336+
});
337+
}
327338

328339
strapi.app.use(router.routes());
329340
},

package-lock.json

Lines changed: 127 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-middleware-cache",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Cache strapi requests",
55
"main": "./lib",
66
"scripts": {
@@ -28,12 +28,14 @@
2828
"lodash": "^4.17.15",
2929
"lru-cache": "^5.1.1",
3030
"pluralize": "^8.0.0",
31-
"redis-lru": "^0.6.0"
31+
"redis-lru": "^0.6.0",
32+
"semver": "^7.3.4"
3233
},
3334
"devDependencies": {
3435
"chai": "^4.2.0",
3536
"koa": "^2.11.0",
3637
"mocha": "^7.1.1",
38+
"sinon": "^9.2.4",
3739
"supertest": "^4.0.2",
3840
"supertest-koa-agent": "^0.3.2"
3941
}

tests/cache.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const initMiddleware = require('../lib/index');
22
const { expect } = require('chai');
33
const agent = require('supertest-koa-agent');
44
const crypto = require('crypto');
5+
const sinon = require('sinon');
56
const {
67
strapi,
78
requests,
@@ -12,6 +13,7 @@ describe('Caching', () => {
1213
let middleware = null;
1314

1415
before(() => {
16+
sinon.stub(process, 'version').value('3.4.0');
1517
strapi.config = {
1618
middleware: {
1719
settings: {
@@ -56,6 +58,8 @@ describe('Caching', () => {
5658
strapi.start();
5759
});
5860

61+
after(() => sinon.restore());
62+
5963
beforeEach(async () => {
6064
await middleware.cache.reset();
6165
reset();
@@ -218,7 +222,7 @@ describe('Caching', () => {
218222

219223
expect(requests).to.have.lengthOf(1);
220224

221-
const res2 = await agent(strapi.app)[method]('/content-manager/explorer/application::academy.academy').expect(200);
225+
const res2 = await agent(strapi.app)[method]('/content-manager/collection-types/application::academy.academy').expect(200);
222226

223227
expect(res2.body.uid).to.equal(res1.body.uid + 1);
224228
expect(requests).to.have.lengthOf(2);
@@ -234,7 +238,7 @@ describe('Caching', () => {
234238

235239
expect(requests).to.have.lengthOf(1);
236240

237-
const res2 = await agent(strapi.app)[method]('/content-manager/explorer/application::academy.academy/publish/1').expect(200);
241+
const res2 = await agent(strapi.app)[method]('/content-manager/collection-types/application::academy.academy/publish/1').expect(200);
238242

239243
expect(res2.body.uid).to.equal(res1.body.uid + 1);
240244
expect(requests).to.have.lengthOf(2);
@@ -299,7 +303,7 @@ describe('Caching', () => {
299303

300304
expect(requests).to.have.lengthOf(1);
301305

302-
const res2 = await agent(strapi.app)[method]('/content-manager/explorer/application::homepage.homepage').expect(200);
306+
const res2 = await agent(strapi.app)[method]('/content-manager/single-types/application::homepage.homepage').expect(200);
303307

304308
expect(res2.body.uid).to.equal(res1.body.uid + 1);
305309
expect(requests).to.have.lengthOf(2);

0 commit comments

Comments
 (0)