Skip to content

Commit d0d0793

Browse files
authored
Search and replace policy (#60)
* Added ‘SearchAndReplace’ Apigee policy * Renamed to ‘SearchAndReplaceResponse’ * Fixed typo * Removed any ES6 syntax * Added SearchAndReplaceResponse Apigee policy to sandbox * Added JS file * Updated name * Moved flow in to the TargetEndpoint * Updated the search and replace JS * Debugging basePath and subdomain * Debug context * Debugging proxyRequest and targetRequest * WIP * Added timestamp * WIP * WIP * WIP * WIP * WIP * Using target.name in API host name * Removed switch statement * Using a request.url * Removed targetName * Updated JS * Added check for ‘api.nhs.uk’ too * Added api.nhs.uk * Added a check for ‘api’ * Added debugging for ‘requestUrl’ and ‘environmentSubdomain’ * Moved ‘item’ variable outside the ‘for’ loop * WIP: AssignMessage.CopyRequest * Commented out the ‘CopyRequest’ flow * Using ‘requestHostnameEnv’ in SearchAndReplaceResponse.js * Debugging ‘requestHostnameEnv’ variable * Removed debugging * Updated the search and replace Regex * Another tweak to the regex * Added spaces back in * Added new search and replace regex
1 parent 4c3bda1 commit d0d0793

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ var searchAndReplaceStrings = [
1414
replaceWithStr:
1515
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1616
},
17+
{
18+
searchForRegex: /:\s?"\/conditions\//gm,
19+
replaceWithStr:
20+
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
21+
},
1722
{
1823
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/conditions\//gm,
1924
replaceWithStr: 'href=\\"https://www.nhs.uk/conditions/',
@@ -35,6 +40,11 @@ var searchAndReplaceStrings = [
3540
replaceWithStr:
3641
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3742
},
43+
{
44+
searchForRegex: /:\s?"\/live-well\//gm,
45+
replaceWithStr:
46+
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
47+
},
3848
{
3949
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/live-well\//gm,
4050
replaceWithStr: 'href=\\"https://www.nhs.uk/live-well/',
@@ -60,6 +70,13 @@ var searchAndReplaceStrings = [
6070
requestHostnameEnv +
6171
"/nhs-website-content/mental-health/",
6272
},
73+
{
74+
searchForRegex: /:\s?"\/mental-health\//gm,
75+
replaceWithStr:
76+
': "https://' +
77+
requestHostnameEnv +
78+
"/nhs-website-content/mental-health/",
79+
},
6380
{
6481
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/mental-health\//gm,
6582
replaceWithStr: 'href=\\"https://www.nhs.uk/mental-health/',
@@ -81,6 +98,11 @@ var searchAndReplaceStrings = [
8198
replaceWithStr:
8299
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
83100
},
101+
{
102+
searchForRegex: /:\s?"\/medicines\//gm,
103+
replaceWithStr:
104+
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
105+
},
84106
{
85107
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/medicines\//gm,
86108
replaceWithStr: 'href=\\"https://www.nhs.uk/medicines/',
@@ -102,6 +124,11 @@ var searchAndReplaceStrings = [
102124
replaceWithStr:
103125
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
104126
},
127+
{
128+
searchForRegex: /:\s?"\/nhs-services\//gm,
129+
replaceWithStr:
130+
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
131+
},
105132
{
106133
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/nhs-services\//gm,
107134
replaceWithStr: 'href=\\"https://www.nhs.uk/nhs-services/',
@@ -123,6 +150,11 @@ var searchAndReplaceStrings = [
123150
replaceWithStr:
124151
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
125152
},
153+
{
154+
searchForRegex: /:\s?"\/pregnancy\//gm,
155+
replaceWithStr:
156+
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
157+
},
126158
{
127159
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/pregnancy\//gm,
128160
replaceWithStr: 'href=\\"https://www.nhs.uk/pregnancy/',
@@ -148,6 +180,13 @@ var searchAndReplaceStrings = [
148180
requestHostnameEnv +
149181
"/nhs-website-content/common-health-questions/",
150182
},
183+
{
184+
searchForRegex: /:\s?"\/common-health-questions\//gm,
185+
replaceWithStr:
186+
': "https://' +
187+
requestHostnameEnv +
188+
"/nhs-website-content/common-health-questions/",
189+
},
151190
{
152191
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/common-health-questions\//gm,
153192
replaceWithStr: 'href=\\"https://www.nhs.uk/common-health-questions/',

0 commit comments

Comments
 (0)