How can i set a client side env var for production on fly
How can i set a client side env var for production on fly? I already deployed so i need to set it .
7 Replies
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To set a client-side environment variable for production on Fly.io after you've already deployed your Wasp application, you can follow these steps:
1. First, it's important to understand that client-side environment variables are embedded into the client code during the build process, not at runtime. This means you can't simply set them on Fly.io after deployment like you would with server-side variables.
2. To set a client-side environment variable, you need to rebuild your application with the new variable. For a Wasp application deployed on Fly.io, you can do this by running the following command:
Replace
REACT_APP_SOME_VAR_NAME
with your actual variable name and somevalue
with the desired value Discord support thread (https://discord.com/channels/686873244791210014/1220070515276775516).
3. This command will rebuild your application with the new environment variable and redeploy it to Fly.io.
4. After redeployment, you should be able to access the environment variable in your client-side code using:
Remember, client-side environment variables are public and can be seen by anyone inspecting your application. Therefore, never use them for secrets or sensitive information Docs > Project > Env Variables > Defining Env Vars in Production (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-production).
If you need to set server-side environment variables (which can be used for secrets), you would use the Fly.io CLI tool instead:
But this is for server-side variables only and is not applicable to your client-side variable question.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?hey, I found another option (more UI). Go to fly and enter in the desired app (only server vars), At the left menu you will see "secrets" you can add or modify them in that tab!
PS: until a new deploy
wasp deploy fly deploy
the secrets doesn't take effect.I find it a bit “safer” for people like me who can cause an issue by putting some wrong command in the console.
I had problems like adding the client var of the Base64 of Google Analytics, break spaces, double quotes
" "
, etc..
With the panel all works fine at ffirst attemptYeah tha js
Thanks
@NEROX the UI you shared will work only for setting the server secrets 🙂 as the bot pointed out - the client env vars are build time and need to be set at the time of deployment in the deployment command. They get "baked in" into the client JS bundle when the client is building.
wops, my bad, It has never been 100% clear to me:sadboi:
Here we write a bit about that process, maybe it will help: https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-production
Env Variables | Wasp
Environment variables are used to configure projects based on the context in which they run. This allows them to exhibit different behaviors in different environments, such as development, staging, or production.