Passing a Client Certificate in webpack proxy

I really like create-react-app. It hides away all of the configuration I don't really need when I am prototyping.

An interesting use case I had recently was an application that needs client authentication. I was surprised to find out that if you started your front end dev server with a certificate and key, it would not automatically pass that to the backend in requests it proxied.

So I had to write my own proxy. Here is a sample way to pass a client certificate to your proxied backend requests whose urls start with /rest :

const fs = require('fs');
const { createProxyMiddleware } = require ('http-proxy-middleware');

module.exports = function (app) {
   app.use(
         '/rest',
         createProxyMiddleware ({
             target: {
                 protocol: 'https',
                 host: HOST,
                 port: PORT,
                 pfx: fs.readFileSync('/path/to/cert'),
                 passphrase: PASSWORD
             }
         })
    );
});