Skip to content

Commit f582373

Browse files
authored
Search and replace policy (#58)
* 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
1 parent 2f75560 commit f582373

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ var searchAndReplaceStrings = [
55
comment1: "=============================================================",
66
comment2: "Conditions ",
77
comment3: "=============================================================",
8-
searchForRegex: /:"https:\/\/api.nhs.uk\/conditions\//gm,
8+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/conditions\//gm,
99
replaceWithStr:
1010
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1111
},
1212
{
13-
searchForRegex: /:"https:\/\/www.nhs.uk\/conditions\//gm,
13+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/conditions\//gm,
1414
replaceWithStr:
1515
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1616
},
@@ -26,12 +26,12 @@ var searchAndReplaceStrings = [
2626
comment1: "=============================================================",
2727
comment2: "Live Well ",
2828
comment3: "=============================================================",
29-
searchForRegex: /:"https:\/\/api.nhs.uk\/live-well\//gm,
29+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/live-well\//gm,
3030
replaceWithStr:
3131
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3232
},
3333
{
34-
searchForRegex: /:"https:\/\/www.nhs.uk\/live-well\//gm,
34+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/live-well\//gm,
3535
replaceWithStr:
3636
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3737
},
@@ -47,12 +47,12 @@ var searchAndReplaceStrings = [
4747
comment1: "=============================================================",
4848
comment2: "Mental health ",
4949
comment3: "=============================================================",
50-
searchForRegex: /:"https:\/\/api.nhs.uk\/mental-health\//gm,
50+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/mental-health\//gm,
5151
replaceWithStr:
5252
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
5353
},
5454
{
55-
searchForRegex: /:"https:\/\/www.nhs.uk\/mental-health\//gm,
55+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/mental-health\//gm,
5656
replaceWithStr:
5757
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
5858
},
@@ -68,12 +68,12 @@ var searchAndReplaceStrings = [
6868
comment1: "=============================================================",
6969
comment2: "Medicines ",
7070
comment3: "=============================================================",
71-
searchForRegex: /:"https:\/\/api.nhs.uk\/medicines\//gm,
71+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/medicines\//gm,
7272
replaceWithStr:
7373
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7474
},
7575
{
76-
searchForRegex: /:"https:\/\/www.nhs.uk\/medicines\//gm,
76+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/medicines\//gm,
7777
replaceWithStr:
7878
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7979
},
@@ -89,12 +89,12 @@ var searchAndReplaceStrings = [
8989
comment1: "=============================================================",
9090
comment2: "NHS services ",
9191
comment3: "=============================================================",
92-
searchForRegex: /:"https:\/\/api.nhs.uk\/nhs-services\//gm,
92+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/nhs-services\//gm,
9393
replaceWithStr:
9494
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
9595
},
9696
{
97-
searchForRegex: /:"https:\/\/www.nhs.uk\/nhs-services\//gm,
97+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/nhs-services\//gm,
9898
replaceWithStr:
9999
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
100100
},
@@ -110,12 +110,12 @@ var searchAndReplaceStrings = [
110110
comment1: "=============================================================",
111111
comment2: "Pregnancy ",
112112
comment3: "=============================================================",
113-
searchForRegex: /:"https:\/\/api.nhs.uk\/pregnancy\//gm,
113+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/pregnancy\//gm,
114114
replaceWithStr:
115115
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
116116
},
117117
{
118-
searchForRegex: /:"https:\/\/www.nhs.uk\/pregnancy\//gm,
118+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/pregnancy\//gm,
119119
replaceWithStr:
120120
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
121121
},
@@ -131,14 +131,14 @@ var searchAndReplaceStrings = [
131131
comment1: "=============================================================",
132132
comment2: "Common health questions ",
133133
comment3: "=============================================================",
134-
searchForRegex: /:"https:\/\/api.nhs.uk\/common-health-questions\//gm,
134+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/common-health-questions\//gm,
135135
replaceWithStr:
136136
':"https://' +
137137
requestHostnameEnv +
138138
"/nhs-website-content/common-health-questions/",
139139
},
140140
{
141-
searchForRegex: /:"https:\/\/www.nhs.uk\/common-health-questions\//gm,
141+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/common-health-questions\//gm,
142142
replaceWithStr:
143143
':"https://' +
144144
requestHostnameEnv +

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ var searchAndReplaceStrings = [
55
comment1: "=============================================================",
66
comment2: "Conditions ",
77
comment3: "=============================================================",
8-
searchForRegex: /:"https:\/\/api.nhs.uk\/conditions\//gm,
8+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/conditions\//gm,
99
replaceWithStr:
1010
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1111
},
1212
{
13-
searchForRegex: /:"https:\/\/www.nhs.uk\/conditions\//gm,
13+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/conditions\//gm,
1414
replaceWithStr:
1515
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1616
},
@@ -26,12 +26,12 @@ var searchAndReplaceStrings = [
2626
comment1: "=============================================================",
2727
comment2: "Live Well ",
2828
comment3: "=============================================================",
29-
searchForRegex: /:"https:\/\/api.nhs.uk\/live-well\//gm,
29+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/live-well\//gm,
3030
replaceWithStr:
3131
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3232
},
3333
{
34-
searchForRegex: /:"https:\/\/www.nhs.uk\/live-well\//gm,
34+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/live-well\//gm,
3535
replaceWithStr:
3636
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3737
},
@@ -47,12 +47,12 @@ var searchAndReplaceStrings = [
4747
comment1: "=============================================================",
4848
comment2: "Mental health ",
4949
comment3: "=============================================================",
50-
searchForRegex: /:"https:\/\/api.nhs.uk\/mental-health\//gm,
50+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/mental-health\//gm,
5151
replaceWithStr:
5252
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
5353
},
5454
{
55-
searchForRegex: /:"https:\/\/www.nhs.uk\/mental-health\//gm,
55+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/mental-health\//gm,
5656
replaceWithStr:
5757
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
5858
},
@@ -68,12 +68,12 @@ var searchAndReplaceStrings = [
6868
comment1: "=============================================================",
6969
comment2: "Medicines ",
7070
comment3: "=============================================================",
71-
searchForRegex: /:"https:\/\/api.nhs.uk\/medicines\//gm,
71+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/medicines\//gm,
7272
replaceWithStr:
7373
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7474
},
7575
{
76-
searchForRegex: /:"https:\/\/www.nhs.uk\/medicines\//gm,
76+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/medicines\//gm,
7777
replaceWithStr:
7878
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7979
},
@@ -89,12 +89,12 @@ var searchAndReplaceStrings = [
8989
comment1: "=============================================================",
9090
comment2: "NHS services ",
9191
comment3: "=============================================================",
92-
searchForRegex: /:"https:\/\/api.nhs.uk\/nhs-services\//gm,
92+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/nhs-services\//gm,
9393
replaceWithStr:
9494
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
9595
},
9696
{
97-
searchForRegex: /:"https:\/\/www.nhs.uk\/nhs-services\//gm,
97+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/nhs-services\//gm,
9898
replaceWithStr:
9999
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
100100
},
@@ -110,12 +110,12 @@ var searchAndReplaceStrings = [
110110
comment1: "=============================================================",
111111
comment2: "Pregnancy ",
112112
comment3: "=============================================================",
113-
searchForRegex: /:"https:\/\/api.nhs.uk\/pregnancy\//gm,
113+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/pregnancy\//gm,
114114
replaceWithStr:
115115
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
116116
},
117117
{
118-
searchForRegex: /:"https:\/\/www.nhs.uk\/pregnancy\//gm,
118+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/pregnancy\//gm,
119119
replaceWithStr:
120120
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
121121
},
@@ -131,14 +131,14 @@ var searchAndReplaceStrings = [
131131
comment1: "=============================================================",
132132
comment2: "Common health questions ",
133133
comment3: "=============================================================",
134-
searchForRegex: /:"https:\/\/api.nhs.uk\/common-health-questions\//gm,
134+
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/common-health-questions\//gm,
135135
replaceWithStr:
136136
':"https://' +
137137
requestHostnameEnv +
138138
"/nhs-website-content/common-health-questions/",
139139
},
140140
{
141-
searchForRegex: /:"https:\/\/www.nhs.uk\/common-health-questions\//gm,
141+
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/common-health-questions\//gm,
142142
replaceWithStr:
143143
':"https://' +
144144
requestHostnameEnv +

0 commit comments

Comments
 (0)