From d49648a8143c36589ab0d37a2a61ee989a326a22 Mon Sep 17 00:00:00 2001 From: sheng <905537351@qq.com> Date: Thu, 25 Jun 2026 12:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Workerman=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 1 + .env.development | 1 + .env.preview | 1 + src/api/workerman/index.js | 3 ++- vue.config.js | 7 +++++++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 30327b79..5ca5da0b 100644 --- a/.env +++ b/.env @@ -21,6 +21,7 @@ VUE_APP_BASE_URL=http://127.0.0.1:22666/background/ # Workerman 接口地址和端口 VUE_APP_WORKERMAN_URL=http://127.0.0.1:34351 +VUE_APP_WORKERMAN_API=/workerman # 部署路径 VUE_APP_PUBLIC_PATH=/dist/ diff --git a/.env.development b/.env.development index 4165cdfc..3e9a6834 100644 --- a/.env.development +++ b/.env.development @@ -9,3 +9,4 @@ VUE_APP_BASE_URL=http://127.0.0.1:22777/background/ # Workerman 接口地址和端口 VUE_APP_WORKERMAN_URL=http://127.0.0.1:34351 +VUE_APP_WORKERMAN_API=/workerman diff --git a/.env.preview b/.env.preview index e9a3d15f..f28ec486 100644 --- a/.env.preview +++ b/.env.preview @@ -14,3 +14,4 @@ VUE_APP_PUBLIC_PATH=/ # Workerman 接口地址和端口 VUE_APP_WORKERMAN_URL=http://127.0.0.1:34351 +VUE_APP_WORKERMAN_API=/workerman diff --git a/src/api/workerman/index.js b/src/api/workerman/index.js index fe613672..3e359ea7 100644 --- a/src/api/workerman/index.js +++ b/src/api/workerman/index.js @@ -2,6 +2,7 @@ import axios from 'axios' import { Message } from 'element-ui' const WORKERMAN_URL = process.env.VUE_APP_WORKERMAN_URL || 'http://127.0.0.1:34351' +const WORKERMAN_API = process.env.VUE_APP_WORKERMAN_API || WORKERMAN_URL const workerman = axios.create({ timeout: 10000, @@ -35,7 +36,7 @@ function buildRequestErrorMessage (error) { } export function sendWorkerman (data) { - return workerman.post(WORKERMAN_URL, normalizePayload(data)).then(response => { + return workerman.post(WORKERMAN_API, normalizePayload(data)).then(response => { const result = response.data const businessError = readBusinessError(result) if (businessError) { diff --git a/vue.config.js b/vue.config.js index 99b57895..48d736e3 100644 --- a/vue.config.js +++ b/vue.config.js @@ -87,6 +87,13 @@ module.exports = { pathRewrite: { '^/background': '' } + }, + '/workerman': { + target: process.env.VUE_APP_WORKERMAN_URL, + changeOrigin: true, + pathRewrite: { + '^/workerman': '' + } } }, disableHostCheck: process.env.NODE_ENV === 'development'