Skip to content

Commit 62e35ab

Browse files
authored
Check if “url” property is at the root or inside the “about” object (#86)
1 parent 59468c5 commit 62e35ab

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

proxies/live/apiproxy/resources/jsc/SearchAndReplaceResponse.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,17 @@ for (var i = 0; i < searchAndReplaceStrings.length; i++) {
224224
}
225225

226226
var responseJsonObj = JSON.parse(responseContent);
227-
responseJsonObj.webpage = responseJsonObj.url.replace(
228-
"https://" + requestHostnameEnv + "/nhs-website-content/",
229-
"https://www.nhs.uk/"
230-
);
227+
if (responseJsonObj.url) {
228+
responseJsonObj.webpage = responseJsonObj.url.replace(
229+
"https://" + requestHostnameEnv + "/nhs-website-content/",
230+
"https://www.nhs.uk/"
231+
);
232+
} else if (responseJsonObj.about.url) {
233+
responseJsonObj.about.webpage = responseJsonObj.about.url.replace(
234+
"https://" + requestHostnameEnv + "/nhs-website-content/",
235+
"https://www.nhs.uk/"
236+
);
237+
}
231238
responseContent = JSON.stringify(responseJsonObj);
232239

233240
context.setVariable("response.content", responseContent);

proxies/sandbox/apiproxy/resources/jsc/SearchAndReplaceResponse.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,17 @@ for (var i = 0; i < searchAndReplaceStrings.length; i++) {
185185
}
186186

187187
var responseJsonObj = JSON.parse(responseContent);
188-
responseJsonObj.webpage = responseJsonObj.url.replace(
189-
"https://api.service.nhs.uk/nhs-website-content/",
190-
"https://www.nhs.uk/"
191-
);
188+
if (responseJsonObj.url) {
189+
responseJsonObj.webpage = responseJsonObj.url.replace(
190+
"https://api.service.nhs.uk/nhs-website-content/",
191+
"https://www.nhs.uk/"
192+
);
193+
} else if (responseJsonObj.about.url) {
194+
responseJsonObj.about.webpage = responseJsonObj.about.url.replace(
195+
"https://api.service.nhs.uk/nhs-website-content/",
196+
"https://www.nhs.uk/"
197+
);
198+
}
192199
responseContent = JSON.stringify(responseJsonObj);
193200

194201
context.setVariable("response.content", responseContent);

0 commit comments

Comments
 (0)