my problem is that the api prefixes requested by the development environment and the production environment are not the same
for example:
Development request address: 192.168.1.100:3000/login
production request address: 192.168.1.200:3000/login
then we need a way to distinguish between address prefixes used in different environments. I have seen two ways on the Internet
1. Set baseURL
to axios according to the process.env.NODE_ENV variableconst getBaseUrl = () => {
const ENV = process.env.NODE_ENV;
if(ENV === "development"){
return "http://192.168.1.100:3000";
}else if(ENV === "production"){
return "http://192.168.1.200:3000";
}
}
const instance = axios.create({
baseURL: getBaseUrl(),
timeout: 10000
});
2. Directly write the address of the online environment to the baseURL of axios, and then the development environment proxies to the test server
"proxy": "http://192.168.1.100:3000"