Created
April 2, 2019 16:26
-
-
Save rajasekarm/0fd3228dc8a5e1446cca6a47d2028b8f to your computer and use it in GitHub Desktop.
axios global config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
const dev = 'http://localhost:4000/api'; | |
const prod = 'http://your_prod_url/api'; | |
const baseURL = process.env.NODE_ENV === 'production' ? prod : dev; | |
const axiosInstance = axios.create({ baseURL, timeout: 30000 }); | |
axiosInstance.interceptors.request.use((config) => { | |
return config; | |
}, error => Promise.reject(error)); | |
axiosInstance.interceptors.response.use(function (response) { | |
return response; | |
}, function (error) { | |
return Promise.reject(error); | |
}); | |
export default axiosInstance; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment