From 25d6308b266a4fef6e03ac1a40e9a43877e2adc4 Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Thu, 9 Nov 2023 12:08:13 -0600 Subject: [PATCH] Update contentMetering middleware to use monorail version --- packages/global/config/content-meter.js | 2 +- sites/ccnewsnow.com/server/routes/content.js | 18 ++++++++++++------ .../server/routes/content.js | 18 ++++++++++++------ .../server/routes/content.js | 18 ++++++++++++------ sites/divhealth.net/server/routes/content.js | 18 ++++++++++++------ 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/packages/global/config/content-meter.js b/packages/global/config/content-meter.js index c46c9b5d..abc203c9 100644 --- a/packages/global/config/content-meter.js +++ b/packages/global/config/content-meter.js @@ -1,5 +1,5 @@ module.exports = { - enable: process.env.ENABLE_CONTENT_METER === 'true', + enabled: process.env.ENABLE_CONTENT_METER === 'true', viewLimit: Number(process.env.CONTENT_METER_VIEW_LIMIT) || 1, excludeLabels: [ 'Sponsored', diff --git a/sites/ccnewsnow.com/server/routes/content.js b/sites/ccnewsnow.com/server/routes/content.js index 246c81fc..a513bd21 100644 --- a/sites/ccnewsnow.com/server/routes/content.js +++ b/sites/ccnewsnow.com/server/routes/content.js @@ -40,15 +40,21 @@ const routesList = [ module.exports = (app) => { const { site } = app.locals; - const contentMeterEnable = site.get('contentMeter.enable'); + const cmConfig = site.getAsObject('contentMeter'); + const contentMeterEnable = cmConfig.enabled; // determin to use newsletterstate or contentMeter middleware routesList.forEach((route) => { if (route.withContentMeter && contentMeterEnable) { - app.get(route.regex, newsletterState({ setCookie: false }), contentMetering(), withContent({ - template: route.template, - queryFragment: route.queryFragment, - formatResponse: formatContentResponse, - })); + app.get( + route.regex, + newsletterState({ setCookie: false }), + contentMetering(cmConfig), + withContent({ + template: route.template, + queryFragment: route.queryFragment, + formatResponse: formatContentResponse, + }), + ); } else { app.get(route.regex, newsletterState({ setCookie: false }), withContent({ template: route.template, diff --git a/sites/diverseeducation.com/server/routes/content.js b/sites/diverseeducation.com/server/routes/content.js index 246c81fc..a513bd21 100644 --- a/sites/diverseeducation.com/server/routes/content.js +++ b/sites/diverseeducation.com/server/routes/content.js @@ -40,15 +40,21 @@ const routesList = [ module.exports = (app) => { const { site } = app.locals; - const contentMeterEnable = site.get('contentMeter.enable'); + const cmConfig = site.getAsObject('contentMeter'); + const contentMeterEnable = cmConfig.enabled; // determin to use newsletterstate or contentMeter middleware routesList.forEach((route) => { if (route.withContentMeter && contentMeterEnable) { - app.get(route.regex, newsletterState({ setCookie: false }), contentMetering(), withContent({ - template: route.template, - queryFragment: route.queryFragment, - formatResponse: formatContentResponse, - })); + app.get( + route.regex, + newsletterState({ setCookie: false }), + contentMetering(cmConfig), + withContent({ + template: route.template, + queryFragment: route.queryFragment, + formatResponse: formatContentResponse, + }), + ); } else { app.get(route.regex, newsletterState({ setCookie: false }), withContent({ template: route.template, diff --git a/sites/diversemilitary.net/server/routes/content.js b/sites/diversemilitary.net/server/routes/content.js index 246c81fc..a513bd21 100644 --- a/sites/diversemilitary.net/server/routes/content.js +++ b/sites/diversemilitary.net/server/routes/content.js @@ -40,15 +40,21 @@ const routesList = [ module.exports = (app) => { const { site } = app.locals; - const contentMeterEnable = site.get('contentMeter.enable'); + const cmConfig = site.getAsObject('contentMeter'); + const contentMeterEnable = cmConfig.enabled; // determin to use newsletterstate or contentMeter middleware routesList.forEach((route) => { if (route.withContentMeter && contentMeterEnable) { - app.get(route.regex, newsletterState({ setCookie: false }), contentMetering(), withContent({ - template: route.template, - queryFragment: route.queryFragment, - formatResponse: formatContentResponse, - })); + app.get( + route.regex, + newsletterState({ setCookie: false }), + contentMetering(cmConfig), + withContent({ + template: route.template, + queryFragment: route.queryFragment, + formatResponse: formatContentResponse, + }), + ); } else { app.get(route.regex, newsletterState({ setCookie: false }), withContent({ template: route.template, diff --git a/sites/divhealth.net/server/routes/content.js b/sites/divhealth.net/server/routes/content.js index 246c81fc..a513bd21 100644 --- a/sites/divhealth.net/server/routes/content.js +++ b/sites/divhealth.net/server/routes/content.js @@ -40,15 +40,21 @@ const routesList = [ module.exports = (app) => { const { site } = app.locals; - const contentMeterEnable = site.get('contentMeter.enable'); + const cmConfig = site.getAsObject('contentMeter'); + const contentMeterEnable = cmConfig.enabled; // determin to use newsletterstate or contentMeter middleware routesList.forEach((route) => { if (route.withContentMeter && contentMeterEnable) { - app.get(route.regex, newsletterState({ setCookie: false }), contentMetering(), withContent({ - template: route.template, - queryFragment: route.queryFragment, - formatResponse: formatContentResponse, - })); + app.get( + route.regex, + newsletterState({ setCookie: false }), + contentMetering(cmConfig), + withContent({ + template: route.template, + queryFragment: route.queryFragment, + formatResponse: formatContentResponse, + }), + ); } else { app.get(route.regex, newsletterState({ setCookie: false }), withContent({ template: route.template,