修改环境配置,根据配置自动选中后端地址,不需要再手动更改

This commit is contained in:
Vectorune
2025-11-11 17:19:34 +08:00
parent 0b6fac8161
commit f40170207a
4 changed files with 20 additions and 9 deletions

4
.env.development Normal file
View File

@ -0,0 +1,4 @@
# 本地后端地址
REACT_APP_BACKEND_ADDRESS=http://localhost:8080
# 超时时间
REACT_APP_BACKEND_TIMEOUT=10000

4
.env.production Normal file
View File

@ -0,0 +1,4 @@
# 远程后端地址
REACT_APP_BACKEND_ADDRESS=http://43.138.83.20:10001
# 超时时间
REACT_APP_BACKEND_TIMEOUT=10000

View File

@ -1,3 +1,3 @@
window.BACKEND_ADDRESS = "http://localhost:8080";
//window.BACKEND_ADDRESS = "http://43.138.83.20:10001";
//window.BACKEND_ADDRESS = "http://localhost:8080";
window.BACKEND_ADDRESS = "http://43.138.83.20:10001";
window.BACKEND_TIMEOUT = 10000;

View File

@ -1,7 +1,10 @@
const baseWebConfig ={
baseUrl: 'http://localhost:8080',
//baseUrl: 'http://43.138.83.20:10001',
timeout: 10000,
}
export default baseWebConfig;
// baseWebConfig.js
const baseWebConfig = {
// 从环境变量读取baseUrl本地开发用localhostbuild用ip:10001
baseUrl: process.env.REACT_APP_BACKEND_ADDRESS,
// 读取超时时间(转成数字类型)
timeout: Number(process.env.REACT_APP_BACKEND_TIMEOUT)
};
console.log('当前环境 baseUrl:', baseWebConfig.baseUrl);
console.log('当前超时时间:', baseWebConfig.timeout);
export default baseWebConfig;