grunt-connect-proxy icon indicating copy to clipboard operation
grunt-connect-proxy copied to clipboard

Proxies not used on Heroku

Open alecook opened this issue 11 years ago • 6 comments

I seem to be having an issue where my proxies do not get picked on Heroku, but work great locally.

Instead on Heroku all requests expected to get proxied just get routed to my Heroku app.

Here is our grunt setup:

var proxyRequest = require('grunt-connect-proxy/lib/utils').proxyRequest;
// Heroku port
var port = process.env.PORT || 3000;

grunt.initConfig({
  connect: {
      server: {
        options: {
          hostname: 'localhost',
          port: 3000,
          base: 'app/',
          debug: true,
          middleware: function (connect, options) {
            return [
              // Configure proxies
              proxyRequest,

              // Serve static files
              connect(connect.static(options.base)).listen(port)
            ];
          }
        },
        proxies: [
          {
            context: '/api',
            host: 'some.proxy.com',
            port: 80,
            https: false,
            changeOrigin: true,
            xforward: false,
          rewrite: {
            '^/api': ''
          }
        }
      ]
    }
  }
});

alecook avatar Oct 24 '13 17:10 alecook

I do not think it would be a wise idea to use the Grunt proxy in production. Can you provide some background on what you are trying to do?

rocky-jaiswal avatar Oct 24 '13 17:10 rocky-jaiswal

Sure, I won't be using this in production it was just a test to try and get a temporary Facebook login working without having to change to much between local calls and deployed calls. The idea was to proxy a request to another app which would return their Facebook login URL.

The reason I decided to post here was that using http-proxy (which I believe this wraps) we were able to get the proxy to work successfully.

alecook avatar Oct 24 '13 17:10 alecook

Oh ok. Sorry, cannot help you for now (need to sleep). Will try and look into it later.

rocky-jaiswal avatar Oct 24 '13 17:10 rocky-jaiswal

Can you post the http-proxy setup that did work, for comparison? it should be the same, but i've also haven't tried running this on heroku, since it's geared for local development.

drewzboto avatar Oct 25 '13 16:10 drewzboto

what would be the best approach instead of grunt proxy in production env?

djindjic avatar Sep 13 '14 10:09 djindjic

I found the solution for this. In your proxies settings you add the headers and change origin vars. Here my proxies options:

  proxies: [
   {
    context: '/api',
    host: 'api.domain.com',
    port: 80,
    changeOrigin: true,
    https: false,
    headers: {
        'host': 'api.domain.com'
    }
   }
  ],

This configuration found for me. I added this in my server option (local develpment) and in my dist settings (generate production files)

pdt: "api.domain.com" is a heroku instances.

nelyj avatar Mar 02 '15 07:03 nelyj