-
Notifications
You must be signed in to change notification settings - Fork 1.2k
How to use environment variables on the client side #1227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So you are wanting to expose a server side environment variable to your client code? How dynamic is the variable? Will it stay the same after the project has been compiled or will it differ depending on the deployment? |
@kingcody Yes, I want to expose a server side environment variable to my client code. The variable is not dynamic, and it will remain the same after compilation (no difference for different compilations). I know that this variable will inevitably be known to the client, but I'd prefer not to check it into version control. Would something like grunt-replace be my best bet? |
If you want to store it client-side without being in Git, you could commit a js file that exposes nothing, and is loaded in index.html. Then, once that file is in Git, add it to your |
@louisscruz , you could also inject your API key at build time. Take a look at this old PR: #757. |
Thank you all for your guidance! |
I have some API keys that are currently stored in controllers and factories. For instance:
Is there a way I can store an API key like this in my local.env.js? Can someone please give me a specific way of doing so?
For deployment, I'd like to set these variables on my server with:
Please forgive my ignorance on this. I come from a rails background, so setting server side variables isn't an issue for me. The problem is client side variables. I've read every issue related to environment variables, local.env, etc., but I'm struggling to get a good understanding of this. If someone informs me how this works, I'll be happy to add some info to the docs.
The text was updated successfully, but these errors were encountered: