apostrophe 4.14.0 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.14.1 (2025-03-31)
4
+
5
+ ### Fixes
6
+
7
+ * Hotfix: fixes a bug in which the same on-demand cache was used across multiple sites in the presence of `@apostrophecms/multisite`. In rare cases, this bug could cause the home page of site "A" to be displayed on a request for site "B," but only if requests were simultaneous. This bug did not impact single-site projects.
8
+
3
9
  ## 4.14.0 (2025-03-19)
4
10
 
5
11
  ### Adds
@@ -156,6 +156,7 @@ const qs = require('qs');
156
156
  const expressBearerToken = require('express-bearer-token');
157
157
  const cors = require('cors');
158
158
  const Promise = require('bluebird');
159
+ const expressCacheOnDemand = require('express-cache-on-demand');
159
160
 
160
161
  module.exports = {
161
162
  async init(self) {
@@ -170,6 +171,7 @@ module.exports = {
170
171
  self.apos.util.error('Set it as a global option (a property of the main object passed to apostrophe).');
171
172
  self.apos.util.error('When you do so other modules will also pick up on it and make URLs absolute.');
172
173
  }
174
+ self.createCacheOnDemand();
173
175
  },
174
176
  tasks(self) {
175
177
  return {
@@ -773,8 +775,14 @@ module.exports = {
773
775
  }
774
776
  }
775
777
  }
776
-
777
778
  self.finalModuleMiddlewareAndRoutes = labeledList.map(item => (item.prepending || []).concat(item.middleware || item.routes)).flat();
779
+ },
780
+ createCacheOnDemand() {
781
+ const { enableCacheOnDemand = true } = self.options;
782
+ if (enableCacheOnDemand) {
783
+ // Instantiate independently for this instance of ApostropheCMS
784
+ self.apos.expressCacheOnDemand = expressCacheOnDemand();
785
+ }
778
786
  }
779
787
  };
780
788
  }
@@ -2,7 +2,6 @@ const _ = require('lodash');
2
2
  const path = require('path');
3
3
  const { klona } = require('klona');
4
4
  const { SemanticAttributes } = require('@opentelemetry/semantic-conventions');
5
- const expressCacheOnDemand = require('express-cache-on-demand')();
6
5
 
7
6
  module.exports = {
8
7
  cascades: [ 'filters', 'batchOperations', 'utilityOperations' ],
@@ -241,9 +240,6 @@ module.exports = {
241
240
  };
242
241
  },
243
242
  async init(self) {
244
- const { enableCacheOnDemand = true } = self.apos
245
- .modules['@apostrophecms/express'].options;
246
- self.enableCacheOnDemand = enableCacheOnDemand;
247
243
  self.typeChoices = self.options.types || [];
248
244
  // If "park" redeclares something with a parkedId present in "minimumPark",
249
245
  // the later one should win
@@ -284,7 +280,7 @@ module.exports = {
284
280
  // `_publishedDoc` property to each draft that also exists in a published form.
285
281
 
286
282
  getAll: [
287
- ...self.enableCacheOnDemand ? [ expressCacheOnDemand ] : [],
283
+ ...self.apos.expressCacheOnDemand ? [ self.apos.expressCacheOnDemand ] : [],
288
284
  async (req) => {
289
285
  await self.publicApiCheckAsync(req);
290
286
  const all = self.apos.launder.boolean(req.query.all);
@@ -410,7 +406,7 @@ module.exports = {
410
406
  // `_home` or `_archive`
411
407
 
412
408
  getOne: [
413
- ...self.enableCacheOnDemand ? [ expressCacheOnDemand ] : [],
409
+ ...self.apos.expressCacheOnDemand ? [ self.apos.expressCacheOnDemand ] : [],
414
410
  async (req, _id) => {
415
411
  _id = self.inferIdLocaleAndMode(req, _id);
416
412
  // Edit access to draft is sufficient to fetch either
@@ -1089,8 +1085,8 @@ database.`);
1089
1085
  addServeRoute() {
1090
1086
  self.apos.app.get('*',
1091
1087
  (req, res, next) => {
1092
- return self.enableCacheOnDemand
1093
- ? expressCacheOnDemand(req, res, next)
1088
+ return self.apos.expressCacheOnDemand
1089
+ ? self.apos.expressCacheOnDemand(req, res, next)
1094
1090
  : next();
1095
1091
  },
1096
1092
  self.serve
@@ -1,5 +1,4 @@
1
1
  const _ = require('lodash');
2
- const expressCacheOnDemand = require('express-cache-on-demand')();
3
2
 
4
3
  module.exports = {
5
4
  extend: '@apostrophecms/doc-type',
@@ -239,12 +238,9 @@ module.exports = {
239
238
  self.addEditorModal();
240
239
  },
241
240
  restApiRoutes(self) {
242
- const { enableCacheOnDemand = true } = self.apos
243
- .modules['@apostrophecms/express'].options;
244
-
245
241
  return {
246
242
  getAll: [
247
- ...enableCacheOnDemand ? [ expressCacheOnDemand ] : [],
243
+ ...self.apos.expressCacheOnDemand ? [ self.apos.expressCacheOnDemand ] : [],
248
244
  async (req) => {
249
245
  await self.publicApiCheckAsync(req);
250
246
  const query = self.getRestQuery(req);
@@ -287,7 +283,7 @@ module.exports = {
287
283
  }
288
284
  ],
289
285
  getOne: [
290
- ...enableCacheOnDemand ? [ expressCacheOnDemand ] : [],
286
+ ...self.apos.expressCacheOnDemand ? [ self.apos.expressCacheOnDemand ] : [],
291
287
  async (req, _id) => {
292
288
  _id = self.inferIdLocaleAndMode(req, _id);
293
289
  await self.publicApiCheckAsync(req);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apostrophe",
3
- "version": "4.14.0",
3
+ "version": "4.14.1",
4
4
  "description": "The Apostrophe Content Management System.",
5
5
  "main": "index.js",
6
6
  "scripts": {