a year ago
I deployed my back end application in springboot and created variables in the deploy instance to represent the environment and normally worked variables. When deploying my react application, the same thing did not happen, I created the environment variable correctly in the deploy instance and the code simply did not regulate the variable even though the names were aligned. Is there a different treatment for variables created in the deploy instance for a react application?
11 Replies
a year ago
please read this docs page for create-react-app https://create-react-app.dev/docs/adding-custom-environment-variables/
tl;dr variables on the frontend service must begin with REACT_APP_
a year ago
I understand, I was already following these guidelines mainly regarding the REACTAPP prefix, even so it still seems that it is not recognizing the environment variable created in the variables session, to access the variables created in railway the code still uses process.env.REACTAPP .. . ?
9 months ago
Same happens to me, any solution??
9 months ago
As the previous mate told you, we have followed the instructions in the document and the problem persists. If you do not know the solution, no problem, but do not refer us to a document which several people have read and it has not solved their problem
9 months ago
Dockerfile
9 months ago
Please read this docs section - https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time
brody
Please read this docs section - https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time
3 months ago
This finally resolved!!
You need to add 2 lines to the dockerfile to create the env variables on the right moment.
Using Variables at Build Time
If you need to use the environment variables that Railway injects at build time, which include variables that you define and Railway-provided variables, you must specify them in the Dockerfile using the ARG
command.
For example:
# Specify the variable you need
ARG RAILWAY_SERVICE_NAME
# Use the varible
RUN echo $RAILWAY_SERVICE_NAME
Be sure to declare your environment variables in the stage they are required in:
FROM node
ARG RAILWAY_ENVIRONMENT
Status changed to Solved brody • 3 months ago