drewzboto / grunt-connect-proxy

Grunt Connect support for proxying API calls during development
MIT License
424 stars 122 forks source link

Proxy to https site error: HPE_INVALID_CONSTANT #117

Closed samsong8610 closed 8 years ago

samsong8610 commented 8 years ago

I need proxy http request to an https site on the localhost. My proxy config is as below.

  proxies: [{
    context: '/gateway',
    host: 'localhost',
    port: 8443,
    https: true,
    secure: false,
    rewrite: {
      '^/gateway': ''
    }
  }],

Start server with grunt -dv serve, access http://localhost:9000/gateway/oauth/authorize using browser, grunt outputs Proxy error: HPE_INVALID_CONSTANT, details as below:

[WS] Catching upgrade event...
Proxied request: /gateway/oauth/authorize -> https://localhost:8443/oauth/authorize
{
  "host": "localhost:9000",
  "user-agent": "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0",
  "accept": "application/json",
  "accept-language": "en-US,en;q=0.5",
  "accept-encoding": "gzip, deflate",
  "dnt": "1",
  "connection": "keep-alive"
}
>> Proxy error:  HPE_INVALID_CONSTANT

The error message in my local https site is http: TLS handshake error from 10.0.2.2:57550: tls: first record does not look like a TLS handshake. It seems like that the proxy dosen't use SSL to connect to the target server.

EDIT: grunt-connect-proxy version is 0.2.0, installed by:

$ npm install grunt-connect-proxy --save-dev
grunt-connect-proxy@0.2.0 node_modules/grunt-connect-proxy
├── lodash@0.9.2
└── http-proxy@1.11.2 (eventemitter3@1.1.1, requires-port@0.0.1)
samsong8610 commented 8 years ago

It works well if installed from github, which is the same version as the previous one.

$ npm install git+https://github.com/drewzboto/grunt-connect-proxy.git --save-dev
grunt-connect-proxy@0.2.0 node_modules/grunt-connect-proxy
├── lodash@0.9.2
└── http-proxy@1.11.2 (eventemitter3@1.1.1, requires-port@0.0.1)
Deklin commented 8 years ago

+1 Same issue tested on 9/21

haugthom commented 8 years ago

It should also work if we install the package not from github. Does anyone know what the problem is?

samsong8610 commented 8 years ago

@snajo IMO, this can be fixed by updating NPM package. With the same version, NPM package has different source code from github.

haugthom commented 8 years ago

@samsong8610 Sure, but in my opinion this isn`t a solution if you are behind a firewall which blocks requests against github. The new source code should deployed to npmjs.org with a increased version number.

samsong8610 commented 8 years ago

@snajo I agree.

siryan2 commented 8 years ago

I´ve the same problem here. It only works if I use "npm install git+https://github.com/drewzboto/grunt-connect-proxy.git --save-dev". Is there any fix available?