I am new to React and need guidance on deploying my front-end application. The app will be served statically from cloud platforms like S3 or Google Cloud Storage, and it interacts with multiple API servers located in the cloud. While developing, I might be using local or testing server URLs. How can I set up reusable API server URLs for different environments such as development, staging, and production?
Solution: I utilized various suggestions and opted for:
- Creating
.env.production
and.env.development
files to define the variableAPI_ENDPOINT = 'host'
- Leveraging create-react-app’s settings to access this in my code as
process.env.API_ENDPOINT
.
Although this practice slightly contradicts 12 Factor App principles by including environment variables in version control, it serves my current needs.