Creating Dynamic URL from JavaScript

I am creating a Dynamic URL based on the headers in JavaScript and setting the target URL in context variable. I am trying to use target variable reference in target endpoint but its not working.

Appreciate for any help.

Thanks,

JavaScript Code:

context.setVariable("target","google.com");

Target endpoint:

<HTTPTargetConnection> 
   <LoadBalancer>     
 	<Server>{target}<Server  />     
   </LoadBalancer>    
<Path>/test</Path>  
</HTTPTargetConnection>


<HTTPTargetConnection> 
   <LoadBalancer>     
 	<Server name="target" />     
   </LoadBalancer>    
<Path>/test</Path>  
</HTTPTargetConnection>




0 2 2,573
2 REPLIES 2

construct the desired targeturl and assign to target.url which will take care of routing.

context.setVariable("target.url", targeturl );

Make sure JS is in request flow of the target endpoint.

You cannot do this:

<HTTPTargetConnection> 
   <LoadBalancer>     
 	<Server>{target}<Server/>  <!-- no no no -->
   </LoadBalancer>    
   <Path>/test</Path>  
</HTTPTargetConnection>

You must use a fixed name for the target. It looks like this:

<HTTPTargetConnection> 
   <LoadBalancer>     
 	<Server name='my_target1'/> <!-- yes, but also no -->
   </LoadBalancer>    
   <Path>/test</Path>  
</HTTPTargetConnection>

But it is an anti-pattern to configure a load-balancer with a single target server. You should use multiple targets with a load balancer. like this:

<HTTPTargetConnection>
    <LoadBalancer>
      <Algorithm>RoundRobin</Algorithm>
      <Server name="target1" />
      <Server name="target2" />
      <MaxFailures>5</MaxFailures>
    </LoadBalancer> 
    <Path>/test</Path>  

    ...

And don't forget to include the HealthMonitor.