I'm building an app hosted on a kubernetes cluster. My app serves a javascript file to the clients. The file contains something like this:
const URL = "https://fancy.com";
async function doSomething() {
// ...Do something here...
let res = await fetch(`${URL}/v1/pizza?${params}`);
return await res.json();
}
The javascript file is embedded in a Docker image, and the backend (written in Go with Gin) simply sends it to the client whenever the client accesses the index page. The backend is behind a ningx load balancer.
Now, I'm building a dev
environment and obviously the javascript above won't work without modification. It needs to contain:
const URL = "https://dev.fancy.com";
Is there a good way to serve the right javascript (ie: with the right url) without building a different image or duplicating the javascript code? I'm mostly a backend dev so sorry if this question is naive.