From 425218908e5c7e5c91622250a1f87fe5f5b3b0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Thu, 4 Jan 2024 22:31:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Bbs.Vue3/.env.development | 13 ++++++------- Yi.Bbs.Vue3/.env.production | 14 +++++++------- Yi.Bbs.Vue3/package.json | 1 + Yi.Bbs.Vue3/vite.config.js | 23 +++++++++++++++++++++-- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Yi.Bbs.Vue3/.env.development b/Yi.Bbs.Vue3/.env.development index 18bc139b..fa1e6cbf 100644 --- a/Yi.Bbs.Vue3/.env.development +++ b/Yi.Bbs.Vue3/.env.development @@ -1,11 +1,10 @@ -# 接口前缀 -VITE_APP_BASEAPI="/api-dev" -VITE_APP_URL="http://123.207.63.87:19001/api/app" -# VITE_APP_URL="http://localhost:19001/api/app" VITE_APP_ENV_NAME = "dev" +# 接口前缀 +VITE_APP_BASEAPI="/dev-api" +VITE_APP_URL="http://localhost:19001/api/app" + + # ws/开发环境 VITE_APP_BASE_WS = '/dev-ws' - -#长连接 -VITE_APP_BASE_URL_WS='http://localhost:19001/hub' \ No newline at end of file +VITE_APP_BASE_URL_WS="http://localhost:19001/api/app" \ No newline at end of file diff --git a/Yi.Bbs.Vue3/.env.production b/Yi.Bbs.Vue3/.env.production index f8be2a0f..b69d6e43 100644 --- a/Yi.Bbs.Vue3/.env.production +++ b/Yi.Bbs.Vue3/.env.production @@ -1,9 +1,9 @@ -# 接口前缀 -VITE_APP_BASEAPI="/prod-api" -VITE_APP_URL="http://123.207.63.87:19001/api/app" VITE_APP_ENV_NAME = "pro" -# ws/开发环境 -VITE_APP_BASE_WS = '/dev-ws' -#长连接 -VITE_APP_BASE_URL_WS='http://localhost:19001/hub' \ No newline at end of file +# 接口前缀 +VITE_APP_BASEAPI="/prod-api" +VITE_APP_URL="http://ccnetcore.com:19001/api/app" + +# ws +VITE_APP_BASE_WS = '/prod-ws' +VITE_APP_BASE_URL_WS="http://ccnetcore.com:19001/hub" \ No newline at end of file diff --git a/Yi.Bbs.Vue3/package.json b/Yi.Bbs.Vue3/package.json index 489e93b7..a4e325f4 100644 --- a/Yi.Bbs.Vue3/package.json +++ b/Yi.Bbs.Vue3/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", + "prod": "vite --mode production", "preview": "vite preview" }, "dependencies": { diff --git a/Yi.Bbs.Vue3/vite.config.js b/Yi.Bbs.Vue3/vite.config.js index a4996fbe..a3a3a9bb 100644 --- a/Yi.Bbs.Vue3/vite.config.js +++ b/Yi.Bbs.Vue3/vite.config.js @@ -33,13 +33,32 @@ export default defineConfig(({ command, mode }) => { [env.VITE_APP_BASEAPI]: { target: env.VITE_APP_URL, changeOrigin: true, - rewrite: (path) => path.replace(/^\/api-dev/, ""), + rewrite: (path) => path.replace(`${[env.VITE_APP_BASEAPI]}`, ""), + + //查看真实代理url + // bypass(req, res, options) { + + // const proxyUrl = options.target + options.rewrite(req.url); + // console.log(proxyUrl); + // req.headers['X-req-proxyURL'] = proxyUrl; + // res.setHeader('X-req-proxyURL', proxyUrl); + + // } }, [env.VITE_APP_BASE_WS]: { target: env.VITE_APP_BASE_URL_WS, changeOrigin: true, - rewrite: (p) => p.replace(/^\/dev-ws/, ""), + rewrite: (p) => p.replace( `${[env.VITE_APP_BASE_WS]}`, ""), ws: true, + //查看真实代理url + bypass(req, res, options) { + + const proxyUrl = options.target + options.rewrite(req.url); + console.log(proxyUrl); + req.headers['X-req-proxyURL'] = proxyUrl; + res.setHeader('X-req-proxyURL', proxyUrl); + + } }, }, },