ant-design-vue-pro icon indicating copy to clipboard operation
ant-design-vue-pro copied to clipboard

后台接口部署上去,连接API 。前端报错,Proxy error: Could not proxy request

Open above-lilili opened this issue 5 years ago • 4 comments

具误为体错Proxy error: Could not proxy request /code from localhost:8000 to http://xx.xx.xxx.xxx:8003 (ECONNREFUSED).

above-lilili avatar Mar 08 '20 11:03 above-lilili

修改了vue.config.js 里面得devserver proxy 代理地址里

above-lilili avatar Mar 08 '20 11:03 above-lilili

https://github.com/sendya/ant-design-pro-vue/issues/91

sendya avatar Mar 08 '20 12:03 sendya

这个可能是bypass的方法没有添加最后的返回导致的 vue.config.js

module.exports = {
  devServer: {
    proxy: {
      "/api": {
        target: "http://localhost:3000",
        bypass: function(req, res) {
          console.log(req.path);
          console.log(process.env.MOCK);
          if (req.headers.accept.indexOf("html") !== -1) {
            console.log("Skipping proxy for browser request.");
            return "/index.html";
          } else if (process.env.MOCK !== "none") {
            const name = req.path
              .split("/api/")[1]
              .split("/")
              .join("_");
            console.log(name);
            const mock = require(`./mock/${name}`);
            const result = mock(req.method);
            delete require.cache[require.resolve(`./mock/${name}`)];
            return res.send(result);
          }
          return null;
        }
      }
    }
  }

Sometimes you don't want to proxy everything. It is possible to bypass the proxy based on the return value of a function.

In the function you get access to the request, response, and proxy options.

Return null or undefined to continue processing the request with proxy.
Return false to produce a 404 error for the request.
Return a path to serve from, instead of continuing to proxy the request.

sunmd avatar Oct 20 '20 15:10 sunmd

修改了vue.config.js 里面得devserver proxy 代理地址里 ECONNREFUSED (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.(https://nodejs.org/api/errors.html#errors_common_system_errors) 代理地址要保持和项目在线调试地址一致,否则自己就得保证代理地址真实存在 @above-lilili

blateyang avatar Aug 06 '21 08:08 blateyang