前端请求/authapi/auth/permissions 实际发给后端 /api/auth/permissions 本地和线上配置

VITE_GLOB_API_URL_PREFIX = /authapi

VITE_PROXY = \["/api","http://192.168.50.2:6066","/tms","http://192.168.50.5:6088","/authapi","http://im.auth.com","/s3-pdf","https://anteater-image.s3.us-east-2.amazonaws.com"]

vite.config.ts 文件
复制代码
import { defineConfig } from 'vite'

export default defineConfig({
  server: {
    proxy: {
      '/authapi': {
        target: 'http://im.auth.com',
        changeOrigin: true,
        rewrite: (path) =>
          path.replace(/^\/authapi/, '/api') // 修改这里
      },
       '/tms': {
        target: 'http://192.168.50.5:6088',
        changeOrigin: true,
        rewrite: (path) =>
          path.replace(/^\/tms/, '/api') // 修改这里
      }
    }
  }
})
线上(Nginx)配置(必须对称
复制代码
location /authapi/ {
    proxy_pass http://im.auth.com/api/;  # ✅ 注意 /api/

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Authorization $http_authorization;
}
location /tms/ {
    proxy_pass http://192.168.50.5:6088/api/;  # ✅ 注意 /api/

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Authorization $http_authorization;
}
本地靠 Vite 的 rewrite,线上靠 Nginx 的 proxy_pass /api/。
相关推荐
天渺工作室1 天前
实现一个adblock/adblock plus等浏览器广告拦截器检测插件
前端·javascript
阳光是sunny1 天前
Vue 项目怎么做用户行为全链路监控?轻量插件方案详解
前端·面试·架构
ZhengEnCi1 天前
Q04-Vite禁用CSS代码分割-解决生产环境样式加载顺序混乱问题
前端·vue.js·vite
九酒1 天前
AI Agent 开发踩坑记:口播功能非得用 APP 原生实现吗?
前端·人工智能·agent
Jackson__1 天前
做了一段时间的AI coding后,我终于搞清了 CLI 和 MCP 的区别
前端·agent·ai编程
IT_陈寒1 天前
JavaScript项目实战经验分享
前端·人工智能·后端
用户47949283569151 天前
6w star,GitHub 趋势第一的 Ponytail,这个agent插件到底在火什么
前端·后端
薛定喵的谔1 天前
我开源了一个精致的 Next.js 博客模板:Skyplume
前端·前端框架·next.js
张龙6871 天前
构建生产级 AI Agent:工具调用与记忆架构实战指南
前端
kyriewen2 天前
2026 年了,还在用 Node.js?Bun 迁移实战:20 分钟搞定,附踩坑记录
前端·javascript·node.js