diff --git a/ilc/server/tailor/configs-injector.js b/ilc/server/tailor/configs-injector.js index 23a7ecef..36223a90 100644 --- a/ilc/server/tailor/configs-injector.js +++ b/ilc/server/tailor/configs-injector.js @@ -11,6 +11,7 @@ module.exports = class ConfigsInjector { #cdnUrl; #jsInjectionPlaceholder = ''; #cssInjectionPlaceholder = ''; + #markedProdTags = /.*?/gims; constructor(newrelic, cdnUrl = null, nrCustomClientJsWrapper = null, nrAutomaticallyInjectClientScript = true) { this.#newrelic = newrelic; @@ -74,7 +75,7 @@ module.exports = class ConfigsInjector { request.styleRefs = this.#getRouteStyleRefsToPreload(registryConfig.apps, slots, template.styleRefs); if (request.ldeRelated) { - document = this.#wrapTagsToRemove(document, /]*>\s*;window\.NREUM[\s\S]*?<\/script>/g); + document = this.#removeProdTags(document); } return document; @@ -251,10 +252,7 @@ module.exports = class ConfigsInjector { return this.#nrCustomClientJsWrapper.replace('%CONTENT%', nrCode); }; - #wrapWithRemoveBeforeParsing = (content) => - `${content}`; - - #wrapTagsToRemove(content, regex) { - return content.replace(regex, (match) => this.#wrapWithRemoveBeforeParsing(match)); + #removeProdTags(content) { + return content.replace(this.#markedProdTags, ''); } }; diff --git a/ilc/server/tailor/configs-injector.spec.js b/ilc/server/tailor/configs-injector.spec.js index ab39f0a3..4d3df967 100644 --- a/ilc/server/tailor/configs-injector.spec.js +++ b/ilc/server/tailor/configs-injector.spec.js @@ -418,7 +418,7 @@ describe('configs injector', () => { }, ); }); - it('should add remove new relic wrap tags if ILC-overrideConfig cookie is present', () => { + it('should remove marked tags for LDE if cookie is present', () => { const overrideConfig = JSON.stringify({ someKey: 'someValue' }); const encodedOverrideConfig = 'LZUTF8:' + LZUTF8.encodeBase64(LZUTF8.compress(overrideConfig)); @@ -438,12 +438,11 @@ describe('configs injector', () => { }, }, () => { - const nrHeader = ``; - const expectedHeader = `${nrHeader}`; + ;NREUM.info={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",licenseKey:"1111",applicationID:"1111",sa:1};`; const configsInjector = new ConfigsInjector(newrelic); const request = { registryConfig, ilcState: { locale: 'en-US' }, ldeRelated: true }; const template = { @@ -464,7 +463,7 @@ describe('configs injector', () => { }; const result = configsInjector.inject(request, template, { slots, reqUrl: '/test/route?a=15' }); - chai.expect(result).to.include(expectedHeader); + chai.expect(result).to.not.include(nrHeader); }, ); });