feat(api): 配置 LED 接口代理与请求地址

- 新增开发及生产环境 LED_API_URL,分别指向本地代理和远程服务器
- 修改 stopReplace 和 numberReplace 请求地址,使用 LED_API_URL,并绕过全局 baseURL
- 在 vite.config.ts 中添加 LED 大屏后端代理配置,支持跨域及路径重写
- 优化开发环境下的接口请求,避免跨域问题
This commit is contained in:
2026-07-20 11:11:57 +08:00
parent a7e88a8f0c
commit 4a91140a76
2 changed files with 17 additions and 5 deletions

View File

@@ -1,11 +1,15 @@
import request from '@/utils/request'; import request from '@/utils/request';
import type { ApiResult } from '@/api'; import type { ApiResult } from '@/api';
import { MODULES_API_URL } from '@/config/setting';
const LED_API_URL = import.meta.env.DEV
? 'http://127.0.0.1:9200/api' // 开发环境走 Vite 代理, 避免跨域
: 'http://16.1.3.234:9200/api';
export async function stopReplace(data: any) { export async function stopReplace(data: any) {
const res = await request.post<ApiResult<unknown>>( const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/led/bme/stop-replace', LED_API_URL + '/led/bme/stop-replace',
data data,
{ baseURL: '' } // 绕过全局 baseURL, 直接访问 LED 后端
); );
if (res.data.code === 0) { if (res.data.code === 0) {
const data = res.data.data; const data = res.data.data;
@@ -16,8 +20,9 @@ export async function stopReplace(data: any) {
export async function numberReplace(data: any) { export async function numberReplace(data: any) {
const res = await request.post<ApiResult<unknown>>( const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/led/bme/number-sources', LED_API_URL + '/led/bme/number-sources',
data data,
{ baseURL: '' } // 绕过全局 baseURL, 直接访问 LED 后端
); );
if (res.data.code === 0) { if (res.data.code === 0) {
const data = res.data.data; const data = res.data.data;

View File

@@ -69,6 +69,13 @@ export default defineConfig(({ command, mode }) => {
cors: true, // 启用 CORS cors: true, // 启用 CORS
// 代理配置 // 代理配置
proxy: { proxy: {
// LED 大屏后端代理
'/led-api': {
target: 'http://16.1.3.234:9200',
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/led-api/, '/api')
},
'/api': { '/api': {
target: target:
env.VITE_API_URL || env.VITE_API_URL ||