From d5b32e384943889833007992c4c8fde578868d1c Mon Sep 17 00:00:00 2001 From: liyongde <1419499670@qq.com> Date: Wed, 8 Jul 2026 15:56:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lefthook.yml | 42 +++++++++++++++++++ .../apps/web-antdv-next/.env.development | 2 +- .../apps/web-antdv-next/vite.config.ts | 33 ++++++++++----- 3 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 lefthook.yml diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 00000000..f6f019e5 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,42 @@ +# EXAMPLE USAGE: +# +# Refer for explanation to following link: +# https://lefthook.dev/configuration/ +# +# pre-push: +# jobs: +# - name: packages audit +# tags: +# - frontend +# - security +# run: yarn audit +# +# - name: gems audit +# tags: +# - backend +# - security +# run: bundle audit +# +# pre-commit: +# parallel: true +# jobs: +# - run: yarn eslint {staged_files} +# glob: "*.{js,ts,jsx,tsx}" +# +# - name: rubocop +# glob: "*.rb" +# exclude: +# - config/application.rb +# - config/routes.rb +# run: bundle exec rubocop --force-exclusion -- {all_files} +# +# - name: govet +# files: git ls-files -m +# glob: "*.go" +# run: go vet -- {files} +# +# - script: "hello.js" +# runner: node +# +# - script: "hello.go" +# runner: go run diff --git a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/.env.development b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/.env.development index 5c71e36f..bc15f015 100644 --- a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/.env.development +++ b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/.env.development @@ -4,7 +4,7 @@ VITE_PORT=5999 VITE_BASE=/ # 请求路径 -VITE_BASE_URL=http://127.0.0.1:48080 +VITE_BASE_URL=http://192.168.10.14:48080 # 接口地址 VITE_GLOB_API_URL=/admin-api # 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 diff --git a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/vite.config.ts b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/vite.config.ts index a75425fb..9bb9ba87 100644 --- a/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/vite.config.ts +++ b/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/vite.config.ts @@ -1,20 +1,33 @@ +import { loadEnv } from 'vite'; import { defineConfig } from '@vben/vite-config'; -export default defineConfig(async () => { +// @ts-ignore +export default defineConfig(async ({ mode }) => { + const env = loadEnv(mode, process.cwd(), 'VITE_'); + + const baseUrl = env.VITE_BASE_URL || 'http://localhost:48080'; + const apiUrl = env.VITE_GLOB_API_URL || '/admin-api'; + + // 如果 apiUrl 已经是完整 URL(如生产环境),不需要 proxy + // 开发环境 apiUrl 为相对路径(如 /admin-api),通过 proxy 转发 + const isFullUrl = /^https?:\/\//.test(apiUrl); + return { application: {}, vite: { server: { allowedHosts: true, - proxy: { - '/admin-api': { - changeOrigin: true, - rewrite: (path) => path.replace(/^\/admin-api/, ''), - // mock代理目标地址 - target: 'http://localhost:48080/admin-api', - ws: true, - }, - }, + proxy: isFullUrl + ? {} + : { + [apiUrl]: { + changeOrigin: true, + rewrite: (path) => path.replace(new RegExp(`^${apiUrl}`), ''), + // 代理目标地址,从环境变量 VITE_BASE_URL + VITE_GLOB_API_URL 拼接 + target: `${baseUrl}${apiUrl}`, + ws: true, + }, + }, }, }, };