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

js 请求404,如何设置 proxy #15

Closed
honchy opened this issue Oct 26, 2018 · 3 comments
Closed

js 请求404,如何设置 proxy #15

honchy opened this issue Oct 26, 2018 · 3 comments

Comments

@honchy
Copy link

honchy commented Oct 26, 2018

我看源码中已经把 proxy 配置关闭了,现在如何使用 proxy 功能呢?

agent.js

// webpack-tool not need proxy again
    const pluginConfig = Object.assign({}, config, { proxy: false });
    if (utils.isUseMultProcess(agent.baseDir, config)) {
      new MultProcessWebpackServer(agent, pluginConfig).start();
    } else {
      const port = utils.getPort(config.port);
      pluginConfig.port = port;
      new WebpackServer(agent, pluginConfig).start();
    }
@hubcarl
Copy link
Collaborator

hubcarl commented Feb 12, 2019

在 config/config.local.js 里面加上 ,下面是默认配置,可以覆盖。 默认情况是不需要修改的,只有修改 webpack的 publicPath (默认 /public/ ) 时,才需要显示配置 match

config.webpack = {
    proxy: {
      host: `http://127.0.0.1:9000`,
      match: /^\/public\//, // path pattern.
    }
  };

这里的 proxy 是指 在本地开发时,把 egg 应用访问的/public/ 的静态资源请求代理到 独立的webpack 编译的服务 9000 上面,这样可以避免本地开发跨域等问题。

@zwmmm
Copy link

zwmmm commented Apr 19, 2019

@hubcarl 怎么排除某些路径 不做代理 比如 api 开头的路径 不走代理 其他的走代理

@hubcarl
Copy link
Collaborator

hubcarl commented Jul 26, 2019

这里的代理只是静态资源的代理,如果是 api,请在 node 端处理

@hubcarl hubcarl closed this as completed Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants