0

I have an issue with webpack-dev-server when it proxys to my prod env. The production server sends me 'set-cookie' header but it is an array and I don't see it in dev-server's response in the browser.

Also, when I debug I see a lot of headers coming from the prod server, but I have not all of them in the browser. How to make webpack-dev-server to bypass all the headers as is.

Thanks.

2
  • Side comment: webpack-dev-server is not meant to be used in production. A better setup would be for prod server to serve the output of the React application build: in dev from webpack-dev-server (being a reverse proxy for webpack-dev-server) and in prod from disk. Commented Oct 31, 2019 at 5:49
  • I don't use it for production, i need my local env to get data from production, i.e. for debugging, investigating and so on Commented Oct 31, 2019 at 12:30

1 Answer 1

0

In many cases, headers should be automatically copied from the proxy response to the response sent to the browser by http-proxy-middleware. The default behavior of most proxy implementations is to forward headers.

But, you could intercept all of the responses from proxy with the headers and inspect/modify them.

proxy: {
                "**": {
                    target: "http://localhost:8000", // Proxy to backend
                    changeOrigin: true,
                    secure: false,

                    // This handles responses
                    onProxyRes: function (proxyRes, req, res) {
                       
                        // Get all headers from proxy response and write them out to console
                        Object.keys(proxyRes.headers).forEach((key) => {
                            console.log(`${key}: ${proxyRes.headers[key]}`);
                        });
                    }
                },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.