You can use ChatGPT for these types of questions, and also drill down into details after it answers your initial one, for example ask it for alternative solutions and so on .
Below its answer to your question:
In order to get the INTERNET_IDENTITY_CANISTER_ID dynamically in your webpack.config.js file, you can try using the dotenv library to load environment variables from a .env file.
To use the dotenv library, you will first need to install it as a dependency:
Copy code
npm install dotenv
Then, create a .env file in the root of your project and add the INTERNET_IDENTITY_CANISTER_ID variable to it:
Next, you can use the dotenv library to load the variables from the .env file into your Node.js application’s environment by requiring it at the top of your webpack.config.js file:
Copy code
require('dotenv').config();
This will allow you to access the INTERNET_IDENTITY_CANISTER_ID variable using process.env.INTERNET_IDENTITY_CANISTER_ID.
Your webpack.config.js file should then look something like this:
but if you’re doing it in browser and node on server side, you must build your code with all variables rendered into plain text, you can’t query environment variable in the browser because there’s no server-side “process environment” to read this from. So all you can do is make sure to build the distribution of your app with all values included in their correct locations. During CI/CD process people usually bake-in those values, and then in gets deployed to relevant environments (for example in a multi-tenant company where apps get deployed for each enterprise customer separately, all required unique values are written into minified builds during build time). I hope it helps
hmm, it’ll need to pull it from some backend then, because you’re working here with a client side code as I understand, the client would never know if something like canister is changing because it’s on remote servers/nodes. But I’m not a developer in ICP so maybe someone with real knowledge will have advice. I just chimed in with my idea of asking the AI for things that are generic (it sometimes comes up with good information actually I really enjoy using it, can’t wait for GPT-4 public release).
how it’s done in classic microservice architectures where the addresses of servers that the app should connect to, are unknown or can change any time (mobile game let’s say, or a vpn), is that there’s one “central” service that never changes, and its only job is to “know” what other server addresses exist and operational at this specific moment. So all clients will always first as this “indexer” backend which indexes all other servers and knows everything about them (to which countries to serve it, which client profiles, geo locations, etc’) so it’ll respond with current IP or DNS record of the backend that “can serve, current client needs” (when there are many possible backends to connect to). In your case it’ll be a canister that never-ever changes its ID/address whatever it is, that helps clients to locate it. And this simple canister, will be the location where you always put the correct “new address” of the “real workload canister”, so no matter how frequently you change it, client side code will always pull the correct ID of whatever backend you want them all to point at.
I hope it helps it’s architecture related, not ICP specific (cos I know nothing about ICP coding but the concept should work anywhere).
Hi @peterparker I followed the instructions above and it works perfectly
Thank you so much for your time, I know you’re a very busy person (especially this year because of your special project) but you still give your time to answer our questions, we appreciate that.