Question

MERN works locally but I am doing something wrong on my droplet, help

Posted November 6, 2021 37 views
NginxMongoDBReact

My MERN app works perfectly on my local machine but when I moved it onto the droplet I can’t figure out how to communicate with the express server/mongo db.

The express app is running on port 3004. When I try making a POST request through my React app I get this error
xhr.js:210 POST http://localhost:3004/api/photo net::ERR_CONNECTION_REFUSED

my subdomain nginx sites-available file has the following:

...
        location / {
                #my react app, this is working
                proxy_pass http://127.0.0.1:8008;
                include /etc/nginx/proxy_params;
        }
        #is api the right path? guessing here
        location /api {
                proxy_pass http://127.0.0.1:3004;
                include /etc/nginx/proxy_params;
        }
...

I’ve searched all over and have only found tutorials about MERN on local machines, not about deploying on DigitalOcean. Thanks.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

For anyone in the future, this solved my problem (replacing localhost in my client/src/api/index.js with my production url)

https://stackoverflow.com/a/63662614/2140821