【问题标题】:Gruntfile.js with grunt-contrib-connect Proxy error: ECONNRESET带有 grunt-contrib-connect 代理错误的 Gruntfile.js:ECONNRESET
【发布时间】:2015-08-24 20:14:06
【问题描述】:

我终于遇到了一个超出我能力范围的问题,而且内部也没有人非常熟悉手头的问题。我的问题是我试图让 grunt serve/server 在工作中使用windows 7/8 来替换我们当前的 nginx 配置以进行开发。

如果我的 angularjs 前端和 grails 后端都在本地运行,我这样做没有问题,但是当我想通过 grunt 本地运行我的 angularjs 应用程序并让它与我们部署的后端对话时-end at test.domain.net 我收到一个代理错误:ECONNRESET error

我已经尝试了 3 个版本的 grunt-contrib-connect (0.1.10, 0.1.11, 0.2.0); 10 和 11 的错误略有不同,但 2 是我更喜欢的,并且是抛出 ECONNRESET 的原因。

对我来说特别奇怪的是,使用 --stack --verbose 它声称我正在通过代理重定向,但是当我在 chrome 中查看 url 时,它仍在使用本地主机。

当前错误

> Proxied request: /app/orders?limit=15&offset=0 ->
> https://services-test.app.com:443/orders?limit=15&offset=0

> {  
 "host": "services-test.app.com",   "connection": "keep-alive",  
> "cache-control": "max-age=0",   "accept": "application/json,
> text/plain, */*",   "x-auth-token":
> "3an7h1oupnj6e7shfplf06adn8mr8q26",   "if-modified-since": "0",  
> "user-agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36
> (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/5
> 37.36",   "referer": "http://localhost:9000/",   "accept-encoding": "gzip, deflate, sdch",   "accept-language": "en-US,en;q=0.8",  
> "cookie": "_ga=GA1.1.1146585466.1432141723;
> JSESSIONID=5569C3D1BDC2CA2CBF5B72636A9338F4",   "x-forwarded-for":
> "127.0.0.1",   "x-forwarded-port": "80",   "x-forwarded-proto": "http"

> }

> Proxy error:  ECONNRESET

Gruntfile.js 的相关部分(为保护隐私而修改的网址)

// The actual grunt server settings
connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',  //'0.0.0.0',
    livereload: 35729
  },
  proxies: [
    {

      //context: '/api',
      //host: 'localhost',
      //port: 8080,
      //https: false,
      //changeOrigin: false,
      //xforward: false

      context: '/api',
      host: 'services-test.app.com',
      https: true,
      port: 443,
      xforward: true,
      headers: {
        'host': 'services-test.app.com',
        'x-auth-token': '3an7h1oupnj6e7shfplf06adn8mr8q26'
      },
      rewrite: {
        '^/api': ''
      }
    }
  ],
  livereload: {
    options: {
      open: true,
      base: [
        '.tmp',
        '<%= yeoman.app %>'
      ],
      middleware: function(connect, options) {
        if (!Array.isArray(options.base)) {
          options.base = [options.base];
        }

        // Setup the proxy
        var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

        // Serve static files.
        options.base.forEach(function(base) {
          middlewares.push(connect.static(base));
        });

        // Make directory browse-able.
        var directory = options.directory || options.base[options.base.length - 1];
        middlewares.push(connect.directory(directory));

        return middlewares;
      }
    }
  },

这里的stackoverflow Grunt connect proxy rewrite not works in https 是我的确切问题,但这并不能解决我的问题。其他相关帖子 http://www.ngroutes.com/questions/AUuACacna5vEqxqlK1fu/grunt-connect-proxy-proxy-created-but-i-get-a-404.html

这篇文章是为什么我的 gruntfile.js 的标头中包含主机以及为什么 services-test.app.com 显示在我的错误中,而不是本地主机。

最后我看到一些东西说这可能是一个 CORS 问题,虽然这可能是可能的,但我认为 grunt-contrib-connect 的重点是不必对服务器端进行更改。

感谢任何可能帮助我解决此问题的人,抱歉,我今天浏览了很多东西,有点漫无边际。

【问题讨论】:

  • 我也遇到了同样的问题,你找到解决办法了吗?
  • 不,遗憾的是我还没有真正找到真正的解决方案。我目前只是在本地运行这两个应用程序。我相当有信心这是一个跨域问题,但无法弄清楚为什么代理不能像它应该的那样工作。

标签: angularjs grails proxy gruntjs grunt-contrib-connect


【解决方案1】:

所以 grunt-connect-proxy 存储库中有一个错误。它已在此提交中修复:https://github.com/drewzboto/grunt-connect-proxy/commit/f798bbd31b76b039a392b8f1bca55b310a7ac5c9

更新到 repo 中的最新提交为我解决了这个问题。所以你可以这样做或等待新版本的发布。

希望能为您解决问题!

【讨论】:

    【解决方案2】:

    我在控制台中不断收到错误“代理错误:ECONNRESET”。这个solution 降级到版本 0.1.10 的 grunt-connect-proxy 有效。我按照fettblog.eu tutorial 设置代理。

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 2015-07-01
      • 2015-01-25
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 2014-11-19
      相关资源
      最近更新 更多