Skip to content

Commit 91c27da

Browse files
authored
SYN-732: Point 'url' to website page (not the API endpoint) (#79)
* Point 'url' to website page (not the API endpoint) * Adding as ‘webpage’ property * Moved comments in to their own objects * Added a value for the ‘homepage’ in the ‘pyproject.toml’ file
1 parent b72c204 commit 91c27da

3 files changed

Lines changed: 55 additions & 9 deletions

File tree

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var searchAndReplaceStrings = [
55
comment1: "=============================================================",
66
comment2: "Conditions ",
77
comment3: "=============================================================",
8+
},
9+
{
810
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/conditions\//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?"https:\/\/api.nhs.uk\/live-well\//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?"https:\/\/api.nhs.uk\/mental-health\//gm,
6167
replaceWithStr:
6268
': "https://' +
@@ -89,6 +95,8 @@ var searchAndReplaceStrings = [
8995
comment1: "=============================================================",
9096
comment2: "Medicines ",
9197
comment3: "=============================================================",
98+
},
99+
{
92100
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/medicines\//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?"https:\/\/api.nhs.uk\/nhs-services\//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?"https:\/\/api.nhs.uk\/pregnancy\//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?"https:\/\/api.nhs.uk\/common-health-questions\//gm,
171185
replaceWithStr:
172186
': "https://' +
@@ -201,10 +215,19 @@ var responseContent = context.getVariable("response.content");
201215
var regex, item;
202216
for (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+
210233
context.setVariable("response.content", responseContent);

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var searchAndReplaceStrings = [
55
comment1: "=============================================================",
66
comment2: "Conditions ",
77
comment3: "=============================================================",
8+
},
9+
{
810
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/conditions\//gm,
911
replaceWithStr:
1012
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
@@ -26,6 +28,8 @@ var searchAndReplaceStrings = [
2628
comment1: "=============================================================",
2729
comment2: "Live Well ",
2830
comment3: "=============================================================",
31+
},
32+
{
2933
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/live-well\//gm,
3034
replaceWithStr:
3135
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
@@ -47,6 +51,8 @@ var searchAndReplaceStrings = [
4751
comment1: "=============================================================",
4852
comment2: "Mental health ",
4953
comment3: "=============================================================",
54+
},
55+
{
5056
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/mental-health\//gm,
5157
replaceWithStr:
5258
': "https://' +
@@ -72,6 +78,8 @@ var searchAndReplaceStrings = [
7278
comment1: "=============================================================",
7379
comment2: "Medicines ",
7480
comment3: "=============================================================",
81+
},
82+
{
7583
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/medicines\//gm,
7684
replaceWithStr:
7785
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
@@ -93,6 +101,8 @@ var searchAndReplaceStrings = [
93101
comment1: "=============================================================",
94102
comment2: "NHS services ",
95103
comment3: "=============================================================",
104+
},
105+
{
96106
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/nhs-services\//gm,
97107
replaceWithStr:
98108
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
@@ -114,6 +124,8 @@ var searchAndReplaceStrings = [
114124
comment1: "=============================================================",
115125
comment2: "Pregnancy ",
116126
comment3: "=============================================================",
127+
},
128+
{
117129
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/pregnancy\//gm,
118130
replaceWithStr:
119131
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
@@ -135,6 +147,8 @@ var searchAndReplaceStrings = [
135147
comment1: "=============================================================",
136148
comment2: "Common health questions ",
137149
comment3: "=============================================================",
150+
},
151+
{
138152
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/common-health-questions\//gm,
139153
replaceWithStr:
140154
': "https://' +
@@ -162,10 +176,19 @@ var responseContent = context.getVariable("response.content");
162176
var regex, item;
163177
for (var i = 0; i < searchAndReplaceStrings.length; i++) {
164178
item = searchAndReplaceStrings[i];
165-
responseContent = responseContent.replace(
166-
item.searchForRegex,
167-
item.replaceWithStr
168-
);
179+
if (item.searchForRegex && item.replaceWithStr) {
180+
responseContent = responseContent.replace(
181+
item.searchForRegex,
182+
item.replaceWithStr
183+
);
184+
}
169185
}
170186

187+
var responseJsonObj = JSON.parse(responseContent);
188+
responseJsonObj.webpage = responseJsonObj.url.replace(
189+
"https://" + requestHostnameEnv + "/nhs-website-content/",
190+
"https://www.nhs.uk/"
191+
);
192+
responseContent = JSON.stringify(responseJsonObj);
193+
171194
context.setVariable("response.content", responseContent);

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
readme = 'README.md'
1212
license = "MIT"
1313
repository = "https://github.com/NHSDigital/nhs-website-content-api"
14-
homepage = ""
14+
homepage = "https://digital.nhs.uk/developer/api-catalogue/nhs-website-content/v2"
1515
keywords = ["healthcare", "uk", "nhs"] #TODO add additional keywords
1616

1717

0 commit comments

Comments
 (0)