How to enable and view create-react-app proxy logs?
Asked Answered
A

2

13

How can I view detailed logs of all requests and responses being handled by the proxy used by create-react-app?

I don't only want to log some endpoints. Instead, I want to see everything, in as much detail as possible, about what's going through the proxy.

The reason is that I'm getting 403 errors back from the AWS API Gateway server but I'm having trouble reproducing the problem via browser, curl, etc. So I want to get ahold of the actual headers and content going over the wire, to see if my problem might be proxy-related.

Adminicle answered 19/8, 2018 at 5:56 Comment(0)
Z
1

This is what worked for me. I added the two properties logger and logLevel. Amazingly, logLevel is not listed in the documentation anywhere and it seems to have a very high default level.

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

module.exports = function (app) {
    app.use(
        '/api',
        createProxyMiddleware({
            target: process.env.REACT_APP_API,
            changeOrigin: true,
            logger: console,
            logLevel: 'debug',
        }),
    )
}

I have no idea why but any event handlers I pass seem to be ignored and I can't see any console logs from them. After adding these I can see a log line in the console for every request.

Zeiler answered 28/4, 2023 at 16:5 Comment(0)
I
-1

In Create-react-app you can use a custom proxy which is an instance of http-proxy-middleware.

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

module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:5000',
      changeOrigin: true,
    })
  );
};

So you can implement your own LogProvider and Errors events

Insurance answered 25/1, 2021 at 0:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.