Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在.webpackrc.js设置了proxy, npm start工作正常,npm run build后提示404(not found) #1699

Closed
wangcray opened this issue May 19, 2018 · 2 comments

Comments

@wangcray
Copy link

设置如下proxy,供服务访问使用

.webpackrc.js

{
  "proxy": {
    "/atrium": {
      "target": "http://127.0.0.1:5000/api/v1.0/",
      "changeOrigin": true,
      "pathRewrite": { "^/atrium" : "" }
    },
  }
}

services中

export function fetch() {
  return request(`/atrium/commands`);
}

Expected behavior: (预期的正常效果)

npm start,页面加载正常,访问数据工作正常

Actual behavior: (实际效果)

npm run build后,尝试过使用nginx和http-server分别建立服务器,页面加载正常,但不能访问导数据,控制台打印如下:

GET http://127.0.0.1:8900/atrium/commands 404 (Not Found)

Versions of packages used: (哪个库的哪个版本出现的问题)

"dva": "^2.1.0"

@wangcray
Copy link
Author

wangcray commented May 20, 2018

自己奋战了几小时,从nginx端进行proxy搞定了。
但还是不是很懂里面的原理,在.webpackrc.js中定义了proxy,run build后就不起作用了么?

@K68
Copy link

K68 commented May 21, 2018

npm start 是开发调试,webpackrc文件会生效,方便前后端独立开发,绕过跨域等问题

npm build 生成的文件,webpackrc文件不生效,需要根据各自的产品环境做反向代理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants