Skip to content

Commit 4c3bda1

Browse files
authored
Search and replace policy (#59)
* 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
1 parent f582373 commit 4c3bda1

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ var searchAndReplaceStrings = [
77
comment3: "=============================================================",
88
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/conditions\//gm,
99
replaceWithStr:
10-
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
10+
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1111
},
1212
{
1313
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/conditions\//gm,
1414
replaceWithStr:
15-
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
15+
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1616
},
1717
{
1818
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/conditions\//gm,
@@ -28,12 +28,12 @@ var searchAndReplaceStrings = [
2828
comment3: "=============================================================",
2929
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/live-well\//gm,
3030
replaceWithStr:
31-
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
31+
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3232
},
3333
{
3434
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/live-well\//gm,
3535
replaceWithStr:
36-
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
36+
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3737
},
3838
{
3939
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/live-well\//gm,
@@ -49,12 +49,16 @@ var searchAndReplaceStrings = [
4949
comment3: "=============================================================",
5050
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/mental-health\//gm,
5151
replaceWithStr:
52-
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
52+
': "https://' +
53+
requestHostnameEnv +
54+
"/nhs-website-content/mental-health/",
5355
},
5456
{
5557
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/mental-health\//gm,
5658
replaceWithStr:
57-
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
59+
': "https://' +
60+
requestHostnameEnv +
61+
"/nhs-website-content/mental-health/",
5862
},
5963
{
6064
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/mental-health\//gm,
@@ -70,12 +74,12 @@ var searchAndReplaceStrings = [
7074
comment3: "=============================================================",
7175
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/medicines\//gm,
7276
replaceWithStr:
73-
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
77+
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7478
},
7579
{
7680
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/medicines\//gm,
7781
replaceWithStr:
78-
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
82+
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7983
},
8084
{
8185
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/medicines\//gm,
@@ -91,12 +95,12 @@ var searchAndReplaceStrings = [
9195
comment3: "=============================================================",
9296
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/nhs-services\//gm,
9397
replaceWithStr:
94-
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
98+
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
9599
},
96100
{
97101
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/nhs-services\//gm,
98102
replaceWithStr:
99-
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
103+
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
100104
},
101105
{
102106
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/nhs-services\//gm,
@@ -112,12 +116,12 @@ var searchAndReplaceStrings = [
112116
comment3: "=============================================================",
113117
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/pregnancy\//gm,
114118
replaceWithStr:
115-
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
119+
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
116120
},
117121
{
118122
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/pregnancy\//gm,
119123
replaceWithStr:
120-
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
124+
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
121125
},
122126
{
123127
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/pregnancy\//gm,
@@ -133,14 +137,14 @@ var searchAndReplaceStrings = [
133137
comment3: "=============================================================",
134138
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/common-health-questions\//gm,
135139
replaceWithStr:
136-
':"https://' +
140+
': "https://' +
137141
requestHostnameEnv +
138142
"/nhs-website-content/common-health-questions/",
139143
},
140144
{
141145
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/common-health-questions\//gm,
142146
replaceWithStr:
143-
':"https://' +
147+
': "https://' +
144148
requestHostnameEnv +
145149
"/nhs-website-content/common-health-questions/",
146150
},

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ var searchAndReplaceStrings = [
77
comment3: "=============================================================",
88
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/conditions\//gm,
99
replaceWithStr:
10-
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
10+
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1111
},
1212
{
1313
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/conditions\//gm,
1414
replaceWithStr:
15-
':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
15+
': "https://' + requestHostnameEnv + "/nhs-website-content/conditions/",
1616
},
1717
{
1818
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/conditions\//gm,
@@ -28,12 +28,12 @@ var searchAndReplaceStrings = [
2828
comment3: "=============================================================",
2929
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/live-well\//gm,
3030
replaceWithStr:
31-
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
31+
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3232
},
3333
{
3434
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/live-well\//gm,
3535
replaceWithStr:
36-
':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
36+
': "https://' + requestHostnameEnv + "/nhs-website-content/live-well/",
3737
},
3838
{
3939
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/live-well\//gm,
@@ -49,12 +49,16 @@ var searchAndReplaceStrings = [
4949
comment3: "=============================================================",
5050
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/mental-health\//gm,
5151
replaceWithStr:
52-
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
52+
': "https://' +
53+
requestHostnameEnv +
54+
"/nhs-website-content/mental-health/",
5355
},
5456
{
5557
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/mental-health\//gm,
5658
replaceWithStr:
57-
':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/",
59+
': "https://' +
60+
requestHostnameEnv +
61+
"/nhs-website-content/mental-health/",
5862
},
5963
{
6064
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/mental-health\//gm,
@@ -70,12 +74,12 @@ var searchAndReplaceStrings = [
7074
comment3: "=============================================================",
7175
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/medicines\//gm,
7276
replaceWithStr:
73-
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
77+
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7478
},
7579
{
7680
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/medicines\//gm,
7781
replaceWithStr:
78-
':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
82+
': "https://' + requestHostnameEnv + "/nhs-website-content/medicines/",
7983
},
8084
{
8185
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/medicines\//gm,
@@ -91,12 +95,12 @@ var searchAndReplaceStrings = [
9195
comment3: "=============================================================",
9296
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/nhs-services\//gm,
9397
replaceWithStr:
94-
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
98+
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
9599
},
96100
{
97101
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/nhs-services\//gm,
98102
replaceWithStr:
99-
':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
103+
': "https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/",
100104
},
101105
{
102106
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/nhs-services\//gm,
@@ -112,12 +116,12 @@ var searchAndReplaceStrings = [
112116
comment3: "=============================================================",
113117
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/pregnancy\//gm,
114118
replaceWithStr:
115-
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
119+
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
116120
},
117121
{
118122
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/pregnancy\//gm,
119123
replaceWithStr:
120-
':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
124+
': "https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/",
121125
},
122126
{
123127
searchForRegex: /href=\\"https:\/\/api.nhs.uk\/pregnancy\//gm,
@@ -133,14 +137,14 @@ var searchAndReplaceStrings = [
133137
comment3: "=============================================================",
134138
searchForRegex: /:\s?"https:\/\/api.nhs.uk\/common-health-questions\//gm,
135139
replaceWithStr:
136-
':"https://' +
140+
': "https://' +
137141
requestHostnameEnv +
138142
"/nhs-website-content/common-health-questions/",
139143
},
140144
{
141145
searchForRegex: /:\s?"https:\/\/www.nhs.uk\/common-health-questions\//gm,
142146
replaceWithStr:
143-
':"https://' +
147+
': "https://' +
144148
requestHostnameEnv +
145149
"/nhs-website-content/common-health-questions/",
146150
},

0 commit comments

Comments
 (0)