Need host name of my targetserver in my java script.

Not applicable

Hi,

I create one target server having different host name for test and prod servers.

based on the hostname(test/prod) i have to create the complete URLs. i am using javascript policy but couldn't able to figure out how to get hostname of my target server through javascript.

Need help.

0 2 542
2 REPLIES 2

"target.host" variable?

adas
New Member

@Vinay Soni If you are creating the complete URL so that you can send the request to that target url, then there's an easier way to do it. Infact, that's the primary reason why one would use targetservers instead of using hardcoded target endpoint URLs. Here's what you can do:

Define the targetEndpoint such that it refers to a targetserver instead of a inline target url like below:

<TargetEndpoint name="default">
    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="target1" />
        </LoadBalancer>
  </HTTPTargetConnection>
</TargetEndpoint>

Now Apigee Edge, would automatically find out the value of this target server, based on the environment for which the request was made, so you don't have to manage that test and prod hostnames for the target servers or manipulate them through a javascript. Hope this helps.

With targetservers, you can also do load balancing across multiple named targetservers so that your backend is highly available and can failover to a target endpoint if the usual ones are down for maintenance. See more details here: