-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Access Node env variables on both server and client #955
Comments
Hey Just chiming in here to offer some assistance! If you see here: https://github.com/kriasoft/react-starter-kit/blob/master/tools/webpack.config.js#L235 Using the Webpack Define plugin: https://github.com/webpack/docs/wiki/list-of-plugins#defineplugin You can pass in what you need to use within the client etc |
@stay2be take a look at PR #883 that shows how to integrate Redux including passing data from the server to a client. In your |
Thanks for your response. @ShaunBaker Setting the values via Webpack is only possible when the bundle is build, but the config values are retrieved when the app is run (in this case on Heroku via env variables). @koistya This approach looks more suitable for me, I'll have a look at this. |
Given the following example:
The Google Analytics Tracking Id is configured via an environment variable. In the config file I can easily write
process.env.GoogleAnalyticsTrackingId
or whatever.How can I access this value on the client for the npm package 'react-ga', which needs to be initialized in the code
client.js
:Including the config file with other sensitive information on the client is not the way to go and accessing environment variables is also not possible. Hardcoding the value in the config file should be avoided in terms of maintenance.
Creating 'window' variables does also not work, because when the site is rendered on the server, the window object is not available (
components/Html.js
).client.js
Thanks for any hints on this problem.
The text was updated successfully, but these errors were encountered: