Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Overriding target.basepath and target.url via Javascript worked previously, but now not

Not applicable

I was successfully using the following Javascript to override the target.basepath and/or target.url for certain operations that need to a different controller in the target application. This no longer works though as it seems the variables are now read only. Is there a way to get this working again? The javascript is in the target Endpoints Preflow. In the trace on this new release, the "targetUrl" now shows as N/A.

var proxyPathSuffix = context.getVariable("proxy.pathsuffix");
print("proxy.pathsuffix=" + proxyPathSuffix + " ");
var requestVerb = context.getVariable("request.verb");
print("requestVerb=" + requestVerb + " ");
if (!proxyPathSuffix.localeCompare("/special-operation") && !requestVerb.localeCompare("POST")) {
  var targetBasePath = context.getVariable("target.basepath");
  print("targetBasePath=" + targetBasePath + " ");
  if (targetBasePath && targetBasePath.localeCompare("")) {
    var newTargetBasePath = targetBasePath.replace("old-context-path", "new-context-path");
    context.setVariable("target.basepath", newTargetBasePath);
    targetBasePath = context.getVariable("target.basepath");
    print("targetBasePath=" + targetBasePath + " ");
  } else {
    print("ERROR: targetBasePath is null! ")
  }
}

1 7 5,011
7 REPLIES 7