From faf1a50b2b770d78f2574b16a2672267dc259e24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?=
- 👉 https://maimengcloud.com 👈 + 👉 https://maimengcloud.com 👈
@@ -23,7 +23,7 @@ - [前端组件](https://gitee.com/maimengcloud/xm-ui-web) - [后端服务](https://gitee.com/maimengcloud/xm-backend) -- [体验环境](https://maimengcloud.com/xm/m1/) +- [体验环境](https://maimengcloud.com/xm) 登陆界面上选择演示账号登陆(账号密码:demo-branch-01 888888)或者直接扫码登陆,无须注册 - 相关教程b站上搜素[唛盟9哥教你撸前后端代码](https://www.bilibili.com/video/BV111421S72r/?spm_id_from=333.337.search-card.all.click&vd_source=93be23d03863773d50b81112985b9237) @@ -363,38 +363,38 @@ pnpm run dev 此种情况下前端如何把请求转发到本地起的后端工程?主要修改[vite.config.js](vite.config.ts)中的代理实现 假设后端mdp-lcode启动,并监听7014端口 ```js - ['/api/m1/lcode']: { + ['/api/lcode']: { target: 'http://localhost:7014', ws: false, changeOrigin: true, - rewrite: (path) => path.replace(new RegExp(`^/api/m1/lcode`), '/'), + rewrite: (path) => path.replace(new RegExp(`^/api/lcode`), '/'), }, - ['/api/m1/xm']: { + ['/api/xm']: { target: 'http://localhost:7067', ws: false, changeOrigin: true, - rewrite: (path) => path.replace(new RegExp(`^/api/m1/xm`), '/'), + rewrite: (path) => path.replace(new RegExp(`^/api/xm`), '/'), }, ``` -上述代理实现把以/api/m1/lcode 开头的请求地址(举例/api/m1/lcode/user/list)替换为/user/list,并转发到http://localhost:7014地址 -上述代理实现把以/api/m1/xm 开头的请求地址(举例/api/m1/xm/user/list)替换为/user/list,并转发到http://localhost:7067地址 +上述代理实现把以/api/lcode 开头的请求地址(举例/api/lcode/user/list)替换为/user/list,并转发到http://localhost:7014地址 +上述代理实现把以/api/xm 开头的请求地址(举例/api/xm/user/list)替换为/user/list,并转发到http://localhost:7067地址 2. 只启动前端页面工程,后端工程不启动,后端工程使用服务器上的已启动的服务 此种情况下前端如何把请求转发到服务上起的后端服务?主要修改[vite.config.js](vite.config.ts)中的代理实现 ```js - ['/api/m1/lcode']: { + ['/api/lcode']: { target: '服务器上的ip:7014', ws: false, changeOrigin: true, - rewrite: (path) => path.replace(new RegExp(`^/api/m1/lcode`), '/'), + rewrite: (path) => path.replace(new RegExp(`^/api/lcode`), '/'), }, - ['/api/m1/xm']: { + ['/api/xm']: { target: '服务器上的ip:7067', ws: false, changeOrigin: true, - rewrite: (path) => path.replace(new RegExp(`^/api/m1/xm`), '/'), + rewrite: (path) => path.replace(new RegExp(`^/api/xm`), '/'), }, ``` @@ -455,7 +455,7 @@ unrar x dist.rar server 192.168.0.222:7067; } - location /api/m1/xm/ { + location /api/xm/ { #proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -475,7 +475,7 @@ unrar x dist.rar server 192.168.0.222:7014; } - location /api/m1/lcode/ { + location /api/lcode/ { #proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -487,7 +487,7 @@ unrar x dist.rar proxy_next_upstream_tries 1; } ``` -需要特别注意的是 http://api-gate-lcode/后面的这个/不能省略,带/代表将“/api/m1/lcode/”替换成“/”,再转发上送到目标服务器 +需要特别注意的是 http://api-gate-lcode/后面的这个/不能省略,带/代表将“/api/lcode/”替换成“/”,再转发上送到目标服务器 ##### 同理,其它子系统的api也类似lcode一样配置,比如工作流相关的api可以按如下方式配置 ``` @@ -495,7 +495,7 @@ unrar x dist.rar server 192.168.0.222:7080; } - location /api/m1/workflow/ { + location /api/workflow/ { #proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -516,7 +516,7 @@ unrar x dist.rar upstream api-gate { server 192.168.0.222:6101; } - location /api/m1/ { + location /api/ { #proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; diff --git a/src/components/mdp-ui/js/util.js b/src/components/mdp-ui/js/util.js index d01e27df..e46fadbb 100644 --- a/src/components/mdp-ui/js/util.js +++ b/src/components/mdp-ui/js/util.js @@ -208,27 +208,30 @@ export default { * @param {...any} uri * @returns */ - getUri:function(curlDomain,...uri){ - debugger - if(curlDomain.endsWith("/")){ - curlDomain=curlDomain.substr(0,curlDomain.length-1); - } + getUri:function(...uri){ + if(!uri||uri.length==0){ - return curlDomain + return "" } var uris=uri.filter(k=>k && k!="null") var paths=uris.join("/"); + var pathArr=paths.split("://") + if(pathArr.length>1){ + paths=pathArr[1] + } paths=paths.replaceAll(/\/{2,}/g,"/") paths=paths.replaceAll(/#\/#/g,"#") - debugger if(paths.startsWith("/")){ paths=paths.substring(1) } - if(paths){ - return curlDomain+"/"+paths + if(paths.endsWith("/")){ + paths=paths.substring(0,paths.length-1) + } + if(pathArr.length>1){ + return pathArr[0]+"://"+paths }else{ - return curlDomain - } + return paths + } },