Reputation: 65
I have an env file with such format:
REACT_APP_API_URL_API_LOGIN = "http://x.x.x.x:1000/api/loginuser"
REACT_APP_API_URL_API_SIGNUP= "http://x.x.x.x:1000/reg/CheckRegister"
REACT_APP_API_URL_API_FETCH_IMAGE = "http://x.x.x.x:1000/api/userImage"
REACT_APP_API_URL_API_VERIFY_USER = "http://x.x.x.x:1000/reg/RegisterUser"
as you know for privacy reasons I changed IP:PORT
I want to separate my base url, the x.x.x.x:1000
part. because sometimes I need to change it for testing purposes.
I wish to have such thing:
REACT_APP_API_URL_API_BASE = x.x.x.x:1000
REACT_APP_API_URL_API_LOGIN = "http://REACT_APP_API_URL_API_BASE/api/loginuser"
I thought about having 2 different .env
files or defining a constant inside of React but it will make, editing codes harder. since I must search for my all,fetching functions all the time.
how can I use my base url inside of the same .evn
file.
Upvotes: 2
Views: 43
Reputation: 41457
in react .env file, you can use it like this
REACT_APP_API_URL_API_BASE = x.x.x.x:1000
REACT_APP_API_URL_API_LOGIN = http://$REACT_APP_API_URL_API_BASE/api/loginuser
Upvotes: 1