@@ -5,6 +5,8 @@ var searchAndReplaceStrings = [
55 comment1 : "=============================================================" ,
66 comment2 : "Conditions " ,
77 comment3 : "=============================================================" ,
8+ } ,
9+ {
810 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ c o n d i t i o n s \/ / gm,
911 replaceWithStr :
1012 ': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/" ,
@@ -31,6 +33,8 @@ var searchAndReplaceStrings = [
3133 comment1 : "=============================================================" ,
3234 comment2 : "Live Well " ,
3335 comment3 : "=============================================================" ,
36+ } ,
37+ {
3438 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ l i v e - w e l l \/ / gm,
3539 replaceWithStr :
3640 ': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/" ,
@@ -57,6 +61,8 @@ var searchAndReplaceStrings = [
5761 comment1 : "=============================================================" ,
5862 comment2 : "Mental health " ,
5963 comment3 : "=============================================================" ,
64+ } ,
65+ {
6066 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ m e n t a l - h e a l t h \/ / gm,
6167 replaceWithStr :
6268 ': "https://' +
@@ -89,6 +95,8 @@ var searchAndReplaceStrings = [
8995 comment1 : "=============================================================" ,
9096 comment2 : "Medicines " ,
9197 comment3 : "=============================================================" ,
98+ } ,
99+ {
92100 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ m e d i c i n e s \/ / gm,
93101 replaceWithStr :
94102 ': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/" ,
@@ -115,6 +123,8 @@ var searchAndReplaceStrings = [
115123 comment1 : "=============================================================" ,
116124 comment2 : "NHS services " ,
117125 comment3 : "=============================================================" ,
126+ } ,
127+ {
118128 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ n h s - s e r v i c e s \/ / gm,
119129 replaceWithStr :
120130 ': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/" ,
@@ -141,6 +151,8 @@ var searchAndReplaceStrings = [
141151 comment1 : "=============================================================" ,
142152 comment2 : "Pregnancy " ,
143153 comment3 : "=============================================================" ,
154+ } ,
155+ {
144156 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ p r e g n a n c y \/ / gm,
145157 replaceWithStr :
146158 ': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/" ,
@@ -167,6 +179,8 @@ var searchAndReplaceStrings = [
167179 comment1 : "=============================================================" ,
168180 comment2 : "Common health questions " ,
169181 comment3 : "=============================================================" ,
182+ } ,
183+ {
170184 searchForRegex : / : \s ? " h t t p s : \/ \/ a p i .n h s .u k \/ c o m m o n - h e a l t h - q u e s t i o n s \/ / gm,
171185 replaceWithStr :
172186 ': "https://' +
@@ -201,10 +215,19 @@ var responseContent = context.getVariable("response.content");
201215var regex , item ;
202216for ( var i = 0 ; i < searchAndReplaceStrings . length ; i ++ ) {
203217 item = searchAndReplaceStrings [ i ] ;
204- responseContent = responseContent . replace (
205- item . searchForRegex ,
206- item . replaceWithStr
207- ) ;
218+ if ( item . searchForRegex && item . replaceWithStr ) {
219+ responseContent = responseContent . replace (
220+ item . searchForRegex ,
221+ item . replaceWithStr
222+ ) ;
223+ }
208224}
209225
226+ var responseJsonObj = JSON . parse ( responseContent ) ;
227+ responseJsonObj . webpage = responseJsonObj . url . replace (
228+ "https://" + requestHostnameEnv + "/nhs-website-content/" ,
229+ "https://www.nhs.uk/"
230+ ) ;
231+ responseContent = JSON . stringify ( responseJsonObj ) ;
232+
210233context . setVariable ( "response.content" , responseContent ) ;
0 commit comments