修改环境配置,根据配置自动选中后端地址,不需要再手动更改
This commit is contained in:
4
.env.development
Normal file
4
.env.development
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# 本地后端地址
|
||||||
|
REACT_APP_BACKEND_ADDRESS=http://localhost:8080
|
||||||
|
# 超时时间
|
||||||
|
REACT_APP_BACKEND_TIMEOUT=10000
|
||||||
4
.env.production
Normal file
4
.env.production
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# 远程后端地址
|
||||||
|
REACT_APP_BACKEND_ADDRESS=http://43.138.83.20:10001
|
||||||
|
# 超时时间
|
||||||
|
REACT_APP_BACKEND_TIMEOUT=10000
|
||||||
@ -1,3 +1,3 @@
|
|||||||
window.BACKEND_ADDRESS = "http://localhost:8080";
|
//window.BACKEND_ADDRESS = "http://localhost:8080";
|
||||||
//window.BACKEND_ADDRESS = "http://43.138.83.20:10001";
|
window.BACKEND_ADDRESS = "http://43.138.83.20:10001";
|
||||||
window.BACKEND_TIMEOUT = 10000;
|
window.BACKEND_TIMEOUT = 10000;
|
||||||
@ -1,7 +1,10 @@
|
|||||||
|
// baseWebConfig.js
|
||||||
const baseWebConfig = {
|
const baseWebConfig = {
|
||||||
baseUrl: 'http://localhost:8080',
|
// 从环境变量读取baseUrl(本地开发用localhost,build用ip:10001)
|
||||||
//baseUrl: 'http://43.138.83.20:10001',
|
baseUrl: process.env.REACT_APP_BACKEND_ADDRESS,
|
||||||
timeout: 10000,
|
// 读取超时时间(转成数字类型)
|
||||||
}
|
timeout: Number(process.env.REACT_APP_BACKEND_TIMEOUT)
|
||||||
|
};
|
||||||
|
console.log('当前环境 baseUrl:', baseWebConfig.baseUrl);
|
||||||
|
console.log('当前超时时间:', baseWebConfig.timeout);
|
||||||
export default baseWebConfig;
|
export default baseWebConfig;
|
||||||
Reference in New Issue
Block a user