question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxing to local https server with self signed cert

See original GitHub issue

Expected behavior

just proxing requests to the api.

Actual behavior

I get 404 response when insecure proxy is set to the existing resource

Setup

  • http-proxy-middleware: 0.9.1
  • server: browser-sync: 2.15.0

proxy middleware configuration

var proxyMiddleware = require('http-proxy-middleware');
var proxyURL = 'https://portal.dev'; //this is my dev env, running on docker
var authProxy = proxyMiddleware('/rest', {target: proxyURL, secure: false, logLevel: 'debug'});

server mounting

browserSync.init({
              logLevel: "debug",
              https: true, //also tried while it was set to false
              server: {
                  baseDir: outputDir,
                  middleware: [authProxy]
              }             
          });

the logs

[HPM] Context match: "/rest" -> "/rest/version"
[HPM] Proxying "/rest/version": "undefined" -> "https://portal.dev"

the chrome console log:

Failed to load resource: the server responded with a status of 404 (Not Found)

the proxy itself setting is ok, if I change to:

var authProxy = proxyMiddleware('/rest', {target: proxyURL, secure: true, logLevel: 'debug'});

then I get different error which is expected:

[HPM] Context match: "/rest" -> "/rest/version"
[HPM] Proxying "/rest/version": "undefined" -> "https://portal.dev"
[HPM] Proxy error: SELF_SIGNED_CERT_IN_CHAIN. localhost:3000 -> "portal.dev/rest/version"

just to make sure it should work

$ curl https://portal.dev/rest/version --insecure
{"version":"82859f14"}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
kotfilemoncommented, Sep 15, 2016

we found it.

// modify some webpack config options
    var proxy = {
                   '/rest': {
                      target : {
                        host: 'portal.dev',
                        protocol: 'https',
                        port: 80
                        },
                      ignorePath: false,
                      changeOrigin: true,
                      secure: false
                    }
                };
    var myConfig = Object.create(webpackConfig);
    myConfig.devtool = "eval";
    myConfig.debug = true;
    myConfig.proxy = proxy;
    // Start a webpack-dev-server
    new WebpackDevServer(webpack(myConfig), {
        contentBase: "./dist",
        proxy: proxy,
        stats: {
            colors: true
        }
    }).listen(8888, "localhost", function(err) {
        if (err) throw new gutil.PluginError("webpack-dev-server", err);
        gutil.log("[webpack-dev-server]", "http://localhost:8888/webpack-dev-server/index.html");
    });

ignorePath has to be set to false.

thanks for Your interest. 😉

1reaction
kotfilemoncommented, Sep 13, 2016

I also tried with webpack-dev-server (with http-proxy-middleware updated), which also uses http-proxy-middleware

configuration:

var proxy = {
                      '/rest': {
                        target: 'https://portal.dev',
                        secure: false
                      }
                    };
    var myConfig = Object.create(webpackConfig);
    myConfig.devtool = "eval";
    myConfig.debug = true;
    myConfig.proxy = proxy;
    // Start a webpack-dev-server
    new WebpackDevServer(webpack(myConfig), {

        contentBase: "./dist",
        proxy: proxy,
        stats: {
            colors: true
        }
    }).listen(8888, "localhost", function(err) {
        if (err) throw new gutil.PluginError("webpack-dev-server", err);
        gutil.log("[webpack-dev-server]", "http://localhost:8888/webpack-dev-server/index.html");
    });

log:

[HPM] Proxy created: /rest  ->  https://portal.dev

same stuff in the browser I see that resource was not found, erorr 404.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cameronhunter/local-ssl-proxy - GitHub
GitHub - cameronhunter/local-ssl-proxy: Simple SSL HTTP proxy using a self-signed certificate. Intended for local development only.
Read more >
How to use HTTPS for local development - web.dev
What you need to do is to create a certificate and sign it with a CA that is trusted locally by your device...
Read more >
How To Create a Self-Signed SSL Certificate for Nginx in ...
In this guide, we will show you how to set up a self-signed SSL certificate for use with an Nginx web server on...
Read more >
Apache reverse proxy with self-signed certificate - Server Fault
a. SSLProxyCACertificateFile is for the httpd<->tomcat connection and contains the Public Key of the Tomcat Server's self-signed cert. b.
Read more >
Reverse proxy and self-signed certificate - Caddy Community
Two servers Server A Caddy v2.4.6 FQDN with Let's Encrypt TLS certificate reverse proxy to server B on port 881 Server B Caddy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found