How to change endpoints for different stages in javascript [client side]?
<p>I think it might have asked before. But I couldn't find any results based on my search keywords. </p>

<p>In my use case I am configuring endpoints based on stage information [desktop, preprod, prod]. I am using golang for backend. In the backend I use the APP_STAGE environment variable to read the respective configs. For example,</p>

<pre><code>fileName =  APP_STAGE + "-endpoints.cfg"
</code></pre>

<p>And I export the variable before starting the server. </p>

<pre><code>$export APP_STAGE="desktop"
</code></pre>

<p>And desktop-endpoints.cfg will look like this,</p>

<pre><code>{
    "featured" : {
        "httpendpoint": {
            "url": "http://localhost:8081/api/services/featured/"
        }

    },
    "latest" : {
        "httpendpoint": {
            "url": "http://localhost:8081/api/services/latest/"
        }

    }
}
</code></pre>

<p>But how can I achieve this in client side [javascript]? I have files in the following structure,</p>

<pre><code>app/
    view.js
    featured.js
    home.js
</code></pre>

<p>Each of the file uses different endpoints to make ajax calls. How can read the stage config based on some variable [if not env variable] in javascript?</p>

<p>Could someone help me with this? I am fairly new to javascript.</p>

<p>Thanks.</p>