Can I add cookies to a webpack dev server proxy?

If you need to only rewrite the cookie domain for the proxy, check out the option cookieDomainRewrite in node-http-proxy.

Additionally if you wanted to find a way to inject in custom behavior around cookies on requests / responses, then check out the events you can hook in to:

proxy.on('proxyRes', function (proxyRes, req, res) {
    console.log('RAW Response from the target',JSON.stringify(proxyRes.headers, true, 2));
});


proxy.on('proxyReq', function (proxyRes, req, res) {
    console.log('RAW Request from the target',JSON.stringify(proxyReq.headers, true, 2));
});

https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events

These options can be added to the webpack.config.js for the devServer proxy, like this:

{
    devServer: {
        proxy: {
            onProxyReq: function(proxyReq, req, res){
                proxyReq.setHeader('x-added', 'foobar');
            },
            cookieDomainRewrite: ""
        }
    }
}

https://github.com/chimurai/http-proxy-middleware#http-proxy-events


After looking into this further, it does seem like the dev server will just forward any cookies you send it. Didn't work for the authentication I was trying to do, I guess Amazon has some more security in place that I couldn't account for, but that is the answer.

Add cookies to the request you're sending to the dev server, and set up the proxy properly.