create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Debug behind an nginx proxy does not work

Open varijkapil13 opened this issue 8 years ago • 3 comments

Is this a bug report?

No

Issue debugging the app behind an nginx proxy

I have an app that is running on localhost:3000. And my Backend API is running on localhost:8181. In order to remove cross-origin requests, and some other compatibility reasons, I set up an nginx reverse proxy for my react app and my backend API. They now both run on localhost:8443.

The Problem: When I create a JavaScript debug configuration in Webstorm for localhost:3000 it works fine. But a configuration for localhost:8443 is not able to debug my react app.

I cannot debug on localhost:3000 because I do not get data from the API there.

I can debug using the console.log() but it would be really nice to have it debug in the IDE itself. I tried searching for a solution but did not find anything helpful for my configuration.

Any pointer to how I can enable the debug for such a configuration?

Here is my proxy_pass configuration for nginx:

 location / {
            proxy_pass   http://localhost:3000;
            proxy_set_header        Host               $host;
            proxy_set_header        X-Real-IP          $remote_addr;
            proxy_set_header        X-Forwarded-For    $proxy_add_x_forwarded_for;
            proxy_http_version      1.1;
            proxy_set_header        Upgrade             $http_upgrade;
            proxy_set_header        Connection          "upgrade";
        }

varijkapil13 avatar Aug 21 '18 15:08 varijkapil13

@varijkapil13 Hey mate, I'm not sure if this will help you but may be instead of nginx try using the WebpackDevServer to proxy API requests to your backend

Have a look at -> https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#proxying-api-requests-in-development

May be this will get the Webstorm debugging to work.

kartiklad avatar Aug 22 '18 05:08 kartiklad

Hey @kartiklad, Thanks for tiur comment, I already tried using the webpack proxy method. The debugging sure works with this method.

But my app is a part of an another app that is built using JSF. It is being converted to React Frontend part by part. So the webpack will let me proxy the requests, but the login mechanism is something that is tricky to perform when using this approach. And I need to disable a few authentication features in order to make the login mechanism work. Tht is the reason I am using nginx on my local development too...

varijkapil13 avatar Aug 22 '18 06:08 varijkapil13

So, turns out the problem was my self-signed certificate. It had localhost.com as Common-Name instead of localhost.

Which can be found out by looking for (java.security.cert.CertificateException: No name matching localhost found) exception in WebStorm logs. (How to find Log files)

I created a new certificate. This time with Common-Name as localhost and the debugging works!

Here is the link to the origianl issue that I opened on Youtrack for Webstorm support. (Link)

Hope this helps someone in the future!

varijkapil13 avatar Aug 23 '18 15:08 varijkapil13