Question

Unable to make API Calls to backend(Node js) from frontend(reactjs)

Hi Team,

We have developed app frontend as React js which has a URL of https://localhost:3000 and node on https://localhost:4000, as per documentation we have configured nginx reverse proxy as below in file path: /etc/nginx/sites-available/default

location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

location / app2 {
        proxy_pass http://localhost:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

so when we make an api calls to node js from react.

example

axios.get('https://localhost:4000/app2/sparters')
.then(res => console.log(res.data))

we are getting error as below : GET http://localhost:4000/app2/spartners 404 not found

Kindly assist on this issue to fix it as soon as possible , so are we doing something wrong or some thing is missing here.

Thanks and Regards, Shivaprasad.G


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer