From 2a7718bb7caefdb9425499c4eb74d6d8bd06ac69 Mon Sep 17 00:00:00 2001 From: Zsuzsa Galusz Date: Fri, 14 Jun 2019 08:19:33 +0200 Subject: [PATCH 1/2] Add support for custom templates --- lib/pxconfig.js | 6 ++++-- lib/pxenforcer.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/pxconfig.js b/lib/pxconfig.js index 575bb589..ce9bc771 100644 --- a/lib/pxconfig.js +++ b/lib/pxconfig.js @@ -33,7 +33,7 @@ class PxConfig { ['CSS_REF', 'cssRef'], ['CUSTOM_LOGO', 'customLogo'], ['SENSITIVE_ROUTES', 'sensitiveRoutes'], ['WHITELIST_ROUTES', 'whitelistRoutes'], ['DYNAMIC_CONFIGURATIONS', 'dynamicConfigurations'], ['MODULE_MODE', 'moduleMode'], ['FIRST_PARTY_ENABLED', 'firstPartyEnabled'], ['ADDITIONAL_ACTIVITY_HANDLER', 'additionalActivityHandler'], ['ENRICH_CUSTOM_PARAMETERS', 'enrichCustomParameters'], ['TESTING_MODE', 'testingMode'], ['WHITELIST_EXT', 'whitelistExt'], ['BYPASS_MONITOR_HEADER', 'bypassMonitorHeader'], ['ADVANCED_BLOCKING_RESPONSE', 'advancedBlockingResponse'], - ['TELEMETRY_COMMAND_HEADER', 'telemetryCommandHeader']]; + ['TELEMETRY_COMMAND_HEADER', 'telemetryCommandHeader'],['CUSTOM_TEMPLATE_ROOT', 'customTemplateRoot'],['CUSTOM_TEMPLATE_DATA', 'customTemplateData']]; configKeyMapping.forEach(([targetKey, sourceKey]) => { this.PX_DEFAULT[targetKey] = PxConfig.configurationsOverriding(this.PX_DEFAULT, params, targetKey, sourceKey); @@ -208,7 +208,9 @@ function pxDefaultConfig(PX_INTERNAL) { WHITELIST_EXT: [], BYPASS_MONITOR_HEADER: '', CONFIG_PATH: '', - ADVANCED_BLOCKING_RESPONSE: true + ADVANCED_BLOCKING_RESPONSE: true, + CUSTOM_TEMPLATE_ROOT: '', + CUSTOM_TEMPLATE_DATA: {} }; } diff --git a/lib/pxenforcer.js b/lib/pxenforcer.js index 69586694..2ea69366 100644 --- a/lib/pxenforcer.js +++ b/lib/pxenforcer.js @@ -329,14 +329,15 @@ class PxEnforcer { hostUrl: hostUrl, jsClientSrc: jsClientSrc, firstPartyEnabled: this._config.FIRST_PARTY_ENABLED, - blockScript: captchaSrc + blockScript: captchaSrc, + customData: this._config.CUSTOM_TEMPLATE_DATA && JSON.stringify(this._config.CUSTOM_TEMPLATE_DATA) }; } compileMustache(template, props, cb) { let htmlTemplate = ''; - mu.root = `${__dirname}/templates`; + mu.root = this._config.CUSTOM_TEMPLATE_ROOT || `${__dirname}/templates`; const compile = mu.compileAndRender(`${template}.mustache`, props); // Building html from template into string variable From 1b2300cb3edb8810d53a4134c7e57d08921c0500 Mon Sep 17 00:00:00 2001 From: Zsuzsa Galusz Date: Fri, 14 Jun 2019 09:15:07 +0200 Subject: [PATCH 2/2] fix linter issues --- lib/pxconfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pxconfig.js b/lib/pxconfig.js index ce9bc771..0bc6e97b 100644 --- a/lib/pxconfig.js +++ b/lib/pxconfig.js @@ -33,7 +33,7 @@ class PxConfig { ['CSS_REF', 'cssRef'], ['CUSTOM_LOGO', 'customLogo'], ['SENSITIVE_ROUTES', 'sensitiveRoutes'], ['WHITELIST_ROUTES', 'whitelistRoutes'], ['DYNAMIC_CONFIGURATIONS', 'dynamicConfigurations'], ['MODULE_MODE', 'moduleMode'], ['FIRST_PARTY_ENABLED', 'firstPartyEnabled'], ['ADDITIONAL_ACTIVITY_HANDLER', 'additionalActivityHandler'], ['ENRICH_CUSTOM_PARAMETERS', 'enrichCustomParameters'], ['TESTING_MODE', 'testingMode'], ['WHITELIST_EXT', 'whitelistExt'], ['BYPASS_MONITOR_HEADER', 'bypassMonitorHeader'], ['ADVANCED_BLOCKING_RESPONSE', 'advancedBlockingResponse'], - ['TELEMETRY_COMMAND_HEADER', 'telemetryCommandHeader'],['CUSTOM_TEMPLATE_ROOT', 'customTemplateRoot'],['CUSTOM_TEMPLATE_DATA', 'customTemplateData']]; + ['TELEMETRY_COMMAND_HEADER', 'telemetryCommandHeader'], ['CUSTOM_TEMPLATE_ROOT', 'customTemplateRoot'], ['CUSTOM_TEMPLATE_DATA', 'customTemplateData']]; configKeyMapping.forEach(([targetKey, sourceKey]) => { this.PX_DEFAULT[targetKey] = PxConfig.configurationsOverriding(this.PX_DEFAULT, params, targetKey, sourceKey);