Reputation: 289
I use create-react-app
with react-script
version 1.0.7
, node 6.10.2
In my project root, I create .env
:
API_ENDPOINT=https://dev-api.com
And in src/common/api.js
, I have:
import axios from 'axios';
const apiEndpoint = process.env.API_ENDPOINT;
axios.defaults.baseURL = apiEndpoint || 'https://prod-api.com';
After building the project with yarn run build
, I check the api call from browser console and it always is https://prod-api.com
.
Do you have any ideas. Thanks
Upvotes: 0
Views: 871