From 6a02dc595c8f877100b5943fb01b029345c4e698 Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Fri, 26 Sep 2025 16:01:42 +0000 Subject: [PATCH] =?UTF-8?q?refactor(api):=20=E5=B0=86=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3ip=E9=85=8D=E7=BD=AE=E5=8A=A0=E5=85=A5config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config.yaml | 4 ++++ backend/flaskApp.py | 4 +++- frontend/api.js | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/config.yaml b/backend/config.yaml index 3892524..9ce8471 100644 --- a/backend/config.yaml +++ b/backend/config.yaml @@ -1,3 +1,7 @@ +backend: + ip: 192.168.193.141 + port: 5000 + model: save_dir: models diff --git a/backend/flaskApp.py b/backend/flaskApp.py index f407d7b..a7ce06c 100644 --- a/backend/flaskApp.py +++ b/backend/flaskApp.py @@ -29,6 +29,8 @@ OUTPUT_DIR = cfg.data.run.output_dir MODELS_DIR = str((CONFIG_PATH.parent / cfg.model.save_dir).resolve()) TRAIN_DIR = cfg.data.train.train_dir TEST_DIR = cfg.data.train.test_dir +BACKEND_IP = cfg.backend.ip +BACKEND_PORT = cfg.backend.port os.makedirs(UPLOAD_DIR, exist_ok=True) executor = ThreadPoolExecutor(max_workers=4) @@ -37,7 +39,7 @@ r = redis.Redis(host="127.0.0.1", port=6379, db=0) # 启动测试服务器 def run_dev(): - app.run(host="192.168.193.141", port=5000) + app.run(host=BACKEND_IP, port=int(BACKEND_PORT)) def set_status(task_id, status, **extra): payload = {"status": status, "updated_at": datetime.datetime.utcnow().isoformat(), **extra} diff --git a/frontend/api.js b/frontend/api.js index 53013a3..b84607a 100644 --- a/frontend/api.js +++ b/frontend/api.js @@ -1 +1,9 @@ -const API_BASE = "http://192.168.193.141:5000/"; \ No newline at end of file +const config = { + server: { + protocol: 'http', + host: '192.168.193.141', + port: 5000 + } +}; + +const API_BASE = `${config.server.protocol}://${config.server.host}:${config.server.port}/`; \ No newline at end of file