Phone Min Khant
Phone Min Khant

Reputation: 21

My React app only routes to http://localhost:4002/api/v1/... api bakend

I deployed a React and Nodejs API backend on different servers. All the servers work well. And I also added the BaseUrl Api route in app-route.js like this -

export const BaseUrl = "http://ec2-11.192.292.19.ap-southeast-1.compute.amazonaws.com/api/v1"

export const Auth_Controller_Login = BaseUrl + "/auth/signin"

But the problem is when I call a react login page from the browser, it freezes and the browser doesn't respond to anything and then I inspected what was wrong. And the error message shows like that -

Failed to load resource: net::ERR_CONNECTION_REFUSED

And also the POST Method from React app only routes to the localhost API backend even though I added the correct nodejs backend BaseUrl. The error shows like that -

POST http://localhost:4002/api/v1/auth/signin net::ERR_CONNECTION_REFUSED

As the error on inspect console shows, the react only routes to localhost. What might possibly seem to be a problem?

Upvotes: 0

Views: 515

Answers (1)

Ashish Kamble
Ashish Kamble

Reputation: 2627

you have to mention full URL like this, replace this lines,

export const BaseUrl = "http://ec2-11.192.292.19.ap-southeast-1.compute.amazonaws.com/api/v1"

export const Auth_Controller_Login = BaseUrl + "/auth/signin"

here still baseUrl is getting wrong, so keep full path,

export const Auth_Controller_Login = "http://ec2-11.192.292.19.ap-southeast-1.compute.amazonaws.com/api/v1/auth/signin"

As BaseUrl still keep pointing to wrong path of http://localhost:4002/api/v1/auth/signin

Upvotes: 2

Related Questions