Umi: 求解大神:proxy 配置不生效

Created on 10 Dec 2018  ·  3Comments  ·  Source: umijs/umi

根据文档介绍,设置了proxy属性如下:

proxy: {
    "/api": {
      "target": "http://api.domain.com/",
      "changeOrigin": true,
      "pathRewrite": { "^/api" : "" }
    }
},

然后本地打包代码:
npm run build

点击登录按钮,调用登录API

export async function userLogin(params) {
  return request('/api/users/login', {
    method: 'POST',
    body: params,
  });
}

出现错误提示:
POST http://localhost/api/users/login 405 (Not Allowed)

提问:

如果设置了Proxy, 访问的URL不应该是: http://api.domain.com/users/login 吗?
然而访问连接并没有生效,还是localhost,我是哪个步骤不正确吗?

Most helpful comment

请问问题解决了吗,是什么原因

解决了,是因为umi proxy功能仅仅是针对于开发阶段,如果真正run build后部署上线,proxy是没有效果的,需要配置nginx或apache,实现proxy的功能;

记得点赞 ... ^-^"

All 3 comments

build proxy 无效(敲黑板)

请问问题解决了吗,是什么原因

请问问题解决了吗,是什么原因

解决了,是因为umi proxy功能仅仅是针对于开发阶段,如果真正run build后部署上线,proxy是没有效果的,需要配置nginx或apache,实现proxy的功能;

记得点赞 ... ^-^"

Was this page helpful?
0 / 5 - 0 ratings