cross-env
, you will not have to do anything special in Frontity. You just need to add it to your package.json
scripts thus:dotenv
only runs in Node, so rather than using an index.js
file you should instead divide the content of your index.js
file across two files, namely client.js
and server.js
.client.js
and server.js
exist, the index.js
file can also still exist but it will be ignored by both the server and the client.dotenv
we must create a .env
file:server.js
and client.js
files (that will each only be executed in the appropriate environment), we are therefore able to privately access the content of the environment variable on the server (for example to perform a request to an external API and storing this data in the state
so it can be accessed from your React components).server.js
file could be something like this:API_TMDB
environment variable is defined in a .env
file included in that projectbeforeSSR
defined in the server.js
) will ensure that your API credentials are secure (i.e. they will not be part of the client bundle) and are only visible to the code running server-side. However, remember to take into account that this logic will be executed in the initialization (or bootstrapping) of the Frontity app (i.e. for any page loaded the first time).state
.frontity.settings.js
or your package state
for that, whichever is more appropriate for your situation.frontity.settings.js
:packages/my-package/src/server.js
:state
and it will be sent to the client for the React hydration.state
will end up in the client. Do not expose any secret API KEY or password.