Gruntfile.js with grunt-contrib-connect Proxy error: ECONNRESET

3.5k views Asked by At

I have finally ran into an issue that is beyond my skill and no-one in house is very familiar with the issue at hand either. My issue is I am attempting to get grunt serve/server working on windows 7/8 at work to replace our current nginx configuration for development.

If I have my angularjs front-end and grails back-end both running locally I have no issues doing this but when I want to run my angularjs app through grunt serve locally and have it talk to our deployed back-end at test.domain.net I am getting a Proxy error: ECONNRESET error.

I have tried 3 versions of grunt-contrib-connect (0.1.10, 0.1.11, 0.2.0); 10 and 11 have slightly different errors but 2 is what I would prefer and is what is throwing the ECONNRESET.

What seems exceptionally strange to me is that with --stack --verbose it claims that I am redirecting through the proxy but when I look at the url in chrome it is still using local host.

Current error

> 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

Pertinent part of Gruntfile.js (urls modified for privacy)

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

This stackoverflow here Grunt connect proxy rewrite not works in https is my exact issue but this does not solve my issue. Other related posts http://www.ngroutes.com/questions/AUuACacna5vEqxqlK1fu/grunt-connect-proxy-proxy-created-but-i-get-a-404.html

this post is why host is included in the headers in my gruntfile.js and why services-test.app.com show in my error at all other than local host.

Lastly I have seen some stuff saying that this might be a CORS issue and while that might be possible the point of grunt-contrib-connect is to not have to make server side changes in my understanding.

Thanks to any who might help me resolve this and sorry it was kind of rambling I've looked through a lot of stuff today.

2

There are 2 answers

0
joerideg On

So there was a bug in the grunt-connect-proxy repository. It was fixed in this commit: https://github.com/drewzboto/grunt-connect-proxy/commit/f798bbd31b76b039a392b8f1bca55b310a7ac5c9

Updating to the latest commit in the repo fixed the problem for me. So you could do that or wait for the new release to come out.

Hope that fixes it for you!

0
Gaʀʀʏ On

I kept getting the error "Proxy error: ECONNRESET" in my console. This solution to downgrade to version 0.1.10 of grunt-connect-proxy worked. I followed this fettblog.eu tutorial on setting the proxy up.