0

My system: git bash on Windows 7

// The actual grunt server settings
    connect: {
      options: {
        port: 8000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost',
        livereload: 35729
      },
      proxies: [
        {
            context: '/api',
            host: 'dev-maps.company.it',
            port: '80',
            https: false,
            changeOrigin: true,
            rewrite: {
              '^/api': '/api'
            }
        }
      ],
      ...

The snippet above is part of my grunt file which gets executed when I use grunt serve. What it does is to proxy the backend api to dev-maps.company.it which is a company internal host that gets resolved through our DNS (and for sure some corporate proxies). My issue is that I'm getting a 404 response.

Now, when I place the URL (dev-maps.company.it) in my browser, it properly resolves. My browser users a "proxy.pac" file which - if I'm not wrong - for this endpoint resolves to DIRECT (meaning no proxy). Through grunt connect however it doesn't seem to be able to resolve it and thus I suspect grunt is using some other proxy.

I verified my git bash doesn't have any proxy environment variable set (like http_proxy or similar). Also, I tried to hack down a quick nodejs app which uses the http package to execute a GET to dev-maps.company.it and it works:

app.get('/api/v1/contexts', function(req, response){
    var prot = options.port == 443 ? https : http;
    var req = prot.request(options, function(res) {
        var output = '';
        console.log(options.host + ':' + res.statusCode);
        res.setEncoding('utf8');

        res.on('data', function (chunk) {
            output += chunk;
        });

        res.on('end', function() {
            var obj = JSON.parse(output);
            response.send(obj);
        });
    });

    req.on('error', function(err) {
        //res.send('error: ' + err.message);
    });

    req.end();
});

Does anyone have an idea where else I could be looking for???

Juri
  • 32,424
  • 20
  • 102
  • 136
  • I'm not sure if I get that right... but do you want to open up a proxy, and then access it by **dev-maps.company.it**, or by **localhost:8000/api** – ddprrt Jun 24 '15 at 11:32
  • @ddprrt I'm launching grunt serve, which serves my app under localhost:8000. The app then makes calls to localhost:8000/api/... which internally should get proxied by grunt-connect-proxy to dev-maps.... – Juri Jun 24 '15 at 13:31
  • Try the config like this: https://gist.github.com/ddprrt/e95f2f45d432cee27772 -- this will route all calls to your connect server, and if the '/api' route is not found, it will forward it to your proxy... – ddprrt Jun 25 '15 at 15:32
  • @ddprrt nope, doesn't work. The point here is which proxy grunt-connect-proxy uses? If I exec a wget to the endpoint from that shell it works, if I start grunt serve which pipes through grunt proxy it doesn't. This means the connect server uses another proxy than the bash shell...? – Juri Jun 26 '15 at 08:56

0 Answers0