Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I proxy to a ssl endpoint with the webpack-dev-server proxy

Tags:

When I try to proxy this http://localhost:9000/rpc request, I receive:

cannot proxy to https://example.appspot.com:80    (write EPROTO  101057795:error:140770FC:SSL routines:   SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794:) 

webpack-dev-derver config:

devServer: {     contentBase: "./",     hostname: 'localhost',     port: 9000,     proxy: {         '/rpc': {             target: 'https://example.appspot.com',             secure: false,             changeOrigin: true     // **Update-2 SOLVED**         }     } } 

I use fetch : fetch('/rpc' ... to make the request and Windows 10 professional to run webpack.

Without the proxy : fetch('https://example.com/rpc' ... the SSL request works fine.

Update. I had to use the SSL port 443 (see the answer of Steffen).
Now using: https://example.appspot.com:443

But still not working with secure: true. The console log shows:

cannot proxy to https://example.appspot.com:443  (Hostname/IP doesn't match certificate's altnames: "Host: localhost.  is not in the cert's altnames: DNS:*.appspot.com, DNS:*.thinkwithgoogle.com, DNS:*.withgoogle.com, DNS:*.withyoutube.com, DNS:appspot.com, DNS:thinkwithgoogle.com, DNS:withgoogle.com, DNS:withyoutube.com") 

And with secure: false. The console reports: 404 (Not Found)

Update: SOLVED using changeOrigin: true. Docs here.

like image 839
voscausa Avatar asked Feb 28 '16 17:02

voscausa


People also ask

What is proxy in webpack?

webpack-dev-server can proxy some requests to others servers. This might be useful for developing API client when you want to send requests to same domain. Proxy is configured via proxy parameter.

How do I use the Webpack Dev Server with a proxy?

Using the Webpack dev server with a proxy does the following: Redirects all your /gdc traffic to the domain set by the --env.gdc parameter (defaults to https://secure.gooddata.com/). Redirects all /*.html requests to the GoodData server. You need this to be able to log in to the platform at https://secure.gooddata.com/account.html.

What is a proxy server in react Webpack?

Setup React Webpack dev server environment. What is a proxy server? A proxy is nothing but a middleman that does the communicating from one computer to another (server). They’re beneficial for increasing security, and increasing performance.

Can I run Webpack-Dev-Server via the API?

While it's recommended to run webpack-dev-server via the CLI, you may also choose to start a server via the API. See the related API documentation for webpack-dev-server.

How do I add Webpack to my project?

Add webpack and its relevant packages to your project. At the root of project folder, create file webpack.config.js. I won't go into details of the configuration as its very basic. "scripts": { "start": "webpack serve --mode development", "build": "webpack --mode production", ... } Now before you try to run the app, configure Babel compiler.


1 Answers

        target: 'https://example.com:80', 

It is very unlikely that port 80 is used for HTTPS. Usually port 443 is used

SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794:) 

It is very likely that the server at port 80 did not reply with HTTPS but with some HTTP error because the message from the client was the start of a TLS handshake and not the expected HTTP request. But the client expected the reply to the TLS handshake and not a HTTP error. That's why you get this error.

Without the proxy : fetch('https://example.com/rpc' ... the SSL request works fine.

That's because you use in this case https://example.com and not https://example.com:80. Because you don't give an explicit port it will use the default port for https, i.e. 443.

like image 86
Steffen Ullrich Avatar answered Sep 21 '22 09:09

Steffen Ullrich