I understand that I can do that easily with TWO ProxyEndpoints and TWO Target Endpoints, but I would have to repeat the Pre and Post flows etc in each ProxyEndpoint and that’s not nice as the whole process is the same.
The issue right now is since the base path in the ProxyEndpoint is set to /services/v1/product
And the route rules are configured like that:
<RouteRule name="Quote Service Rule">
<Condition>(proxy.pathsuffix MatchesPath "/quote/**")</Condition>
<TargetEndpoint>targetQuote</TargetEndpoint>
</RouteRule>
<RouteRule name="Reference Data Service Rule">
<Condition>(proxy.pathsuffix MatchesPath "/ref-data/**")</Condition>
<TargetEndpoint>targetRefData</TargetEndpoint>
</RouteRule>
https://myapigeeurl/services/v1/product/ref-data/stuff the target url invoked is /api/reference-data-service/ref-data/stuff because the proxy.pathsuffix is obviously “ref-data/stuff”
How to strip that off? The target URL invoked should be /api-reference-data/stuff
You can use shared flows if you don’t want to repeat all the policies in different proxy endpoints. Optionally, You can override target url in target endpoint preflow using javascript policy like below,
context.setVariable("target.copy.pathsuffix", false);
var proxySuffix = context.getVariable("proxy.pathsuffix");
var proxySuffixFragments = proxySuffix.split("/");
var targetpathsuffix = proxySuffixFragments.splice(2).join("/");
context.setVariable("targetpathsuffix", targetpathsuffix);
Thank you very much for looking, @Anil Sagar. As you can see, I am using a named target server, I am certain setting the target.url variable has no effect.
Yes, You are right, You cannot override using target.url , but you can append suffix to path in the targetendpoint HTTPTargetConnection element something like below,
context.setVariable("target.copy.pathsuffix", false);
var targetserver = context.getVariable("target.url");
var proxySuffix = context.getVariable("proxy.pathsuffix");
var proxySuffixFragments = proxySuffix.split("/");
// remove the first part
proxySuffixFragments.splice(0, 2);
var targetpathsuffix = proxySuffixFragments.join("/");
var targeturl = targetserver + targetpathsuffix
context.setVariable("targetpathsuffix", targetpathsuffix);