File tree Expand file tree Collapse file tree
proxies/sandbox/apiproxy/resources/jsc Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var response = context . getVariable ( "response.content" ) ;
2+ var json = JSON . parse ( response ) ;
3+
4+ if ( json . place ) {
5+ // Loop over each item in the search result array, re-writing the hostname to that of the initial request
6+ json . place . forEach ( value => {
7+ var request_hostname = context . getVariable ( "request_hostname_env" ) ;
8+ // Annoyingly, Apigee's version of JS doesn't support regex look-behinds,
9+ // so we grab the env string including https:// prefix
10+ var hostname_regex = / ( ^ h t t p s : \/ \/ ( [ a - z A - Z \- ] + \. ) + ) n h s \. u k / gm;
11+ var rewritten_url = value . url . replace ( hostname_regex , "https://" + request_hostname ) ;
12+ value . url = rewritten_url ;
13+ // value.url = value.url.replace("api-version=1", "api-version=2");
14+ // value.url = value.url.replace("service-search", "service-search-api");
15+ } ) ;
16+
17+ // Update the response payload with the corrected urls
18+ context . setVariable ( "message.content" , JSON . stringify ( json ) ) ;
19+ }
You can’t perform that action at this time.
0 commit comments