From f40170207a1ff73108c0b297aaada82486ffd762 Mon Sep 17 00:00:00 2001 From: Vectorune Date: Tue, 11 Nov 2025 17:19:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8E=AF=E5=A2=83=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E6=A0=B9=E6=8D=AE=E9=85=8D=E7=BD=AE=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=89=E4=B8=AD=E5=90=8E=E7=AB=AF=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E9=9C=80=E8=A6=81=E5=86=8D=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 ++++ .env.production | 4 ++++ public/runtime-config.js | 4 ++-- src/config/BaseWebConfig.js | 17 ++++++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 .env.development create mode 100644 .env.production 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