2015-06-09 40 views
2

我终于遇到了一个超出我的技能的问题,而且内部没有人非常熟悉这个问题。我的问题是我试图在工作中使用windows 7/8的grunt服务器/服务器来替换我们当前的nginx配置以进行开发。gruntfile.js与grunt-contrib-connect代理错误:ECONNRESET

如果我有我的angularjs前端和grails后端都在本地运行我没有问题这样做,但是当我想通过本地grunt服务运行我的angularjs应用程序并让它与我们部署的后端进行通信时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时,它仍然使用本地主机。

当前出错

Gruntfile.js的
> 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 

相关部分(修改隐私的网址)

// 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; 
     } 
    } 
    }, 

这个计算器这里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的意义在于不必在我的理解中进行服务器端更改。

感谢任何可能帮助我解决这个问题的人,对不起,这有点散漫,我今天看了很多东西。

+0

我有同样的问题,你找出解决方案吗? – joerideg

+0

不幸的是,我还没有真正找到一个真正的解决方案。我目前刚刚在本地运行两个应用程序。我相当确信这是一个跨域问题,但一直无法弄清楚为什么代理不能像表面上看起来那样工作。 – xtheshadowgod

回答

1

我在控制台中不断收到错误“代理错误:ECONNRESET”。此solution降级到版本0.1.10的grunt-connect-proxy工作。关于设置代理,我遵循此fettblog.eu tutorial