I've created a reverse proxy through apigee UI, now I'd like to change the target URL based on my org name, so I can have a single proxy to deploy on all orgs. Can someone let me know the steps to do this?
proxy.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <TargetEndpoint name="default"> <Description/> <FaultRules/> <PreFlow name="PreFlow"> <Request/> <Response/> </PreFlow> <PostFlow name="PostFlow"> <Request/> <Response/> </PostFlow> <Flows/> <HTTPTargetConnection> <Properties/> <URL>https://STRING_FOR_REPLACEMENT</URL> </HTTPTargetConnection> </TargetEndpoint>
var orgname = context.getVariable("organization.name"); if (orgname == "DEV") { context.setVariable("systemUrl.myURL", "https://myDev.com/"); } if (orgname == "STAGE") { context.setVariable("systemUrl.myURL", "https://myStage.com/"); } if ((orgname == "LIVE") ) { context.setVariable("systemUrl.myURL", "https://live.com/"); } var targetUrl = context.getVariable("target.url"); targetUrl = targetUrl.replace("STRING_FOR_REPLACEMENT", context.getVariable("systemUrl.myURL")); targetUrl += context.getVariable("proxy.pathsuffix"); var querystring = context.getVariable("request.querystring"); if (querystring && (querystring.length > 0)) { targetUrl += "?" + querystring; } #####NOTE#### I'm using ReversePrxoy not NodeJS proxy
@LoganathanSellappa, you can use route rules to route the traffic to different rules based on the organization name.
Or if you are using the above javascript code, you can put a javascript policy at proxy preflow, to set the appropriate url according to the environment. But I suggest, route rules would be a better option to do this.
Also, you can add these urls in a KVM map instead of hardcoding it in your proxy.
@LoganathanSellappa, Use Target Servers to decouple concrete endpoint URLs from API Proxy TargetEndpoint configurations. Pls refer the below link.
https://docs.apigee.com/api-services/content/load-balancing-across-backend-servers