diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..ca0bd93 --- /dev/null +++ b/.env.development @@ -0,0 +1,4 @@ +# 本地后端地址 +REACT_APP_BACKEND_ADDRESS=http://localhost:8080 +# 超时时间 +REACT_APP_BACKEND_TIMEOUT=10000 \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..a2f0161 --- /dev/null +++ b/.env.production @@ -0,0 +1,4 @@ +# 远程后端地址 +REACT_APP_BACKEND_ADDRESS=http://43.138.83.20:10001 +# 超时时间 +REACT_APP_BACKEND_TIMEOUT=10000 \ No newline at end of file diff --git a/public/runtime-config.js b/public/runtime-config.js index 22fbb82..3a4e103 100644 --- a/public/runtime-config.js +++ b/public/runtime-config.js @@ -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; \ No newline at end of file diff --git a/src/config/BaseWebConfig.js b/src/config/BaseWebConfig.js index ba1f459..8014728 100644 --- a/src/config/BaseWebConfig.js +++ b/src/config/BaseWebConfig.js @@ -1,7 +1,10 @@ -const baseWebConfig ={ - baseUrl: 'http://localhost:8080', - //baseUrl: 'http://43.138.83.20:10001', - timeout: 10000, -} - -export default baseWebConfig; \ No newline at end of file +// baseWebConfig.js +const baseWebConfig = { + // 从环境变量读取baseUrl(本地开发用localhost,build用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; \ No newline at end of file