title: How to route requests to desired endpoint using Environment Variables in APIGEE
body: <p>I've a situation where I need to route requests to desired endpoint based on Environment the request hits. for example QA - QA, Prod to Prod</p>
  
  <p>I've configured a proxy and defined a default target host during initial config.</p>
  
  <p>Then I'm using a javascript to decide target host based on the env the request comes in.</p>
  
  <pre><code>var env = context.getVariable('environment.name');  
  
  if(env=="prod") {
       var host = 'https://prod.com';
  }
  if(env=="test") {
       var host = 'https://qa.com';
  }
  </code></pre>
  
  <p>I've used this JS file in target endpoint(default) preflow as a step.</p>
  
  <p>I see that all requests are sent to the default host that I configured during initial process.</p>
  
  <p>Am I missing something here please help.</p>
  
  <p>Also I've seen about using Target Server Env config. I've configured the hosts but how do I reference/use it in my proxy. </p>