I have a React Web Application and a NodeJS Server, both deployed to Ubuntu EC2 instances. I've confirmed that API calls can be made between them using a CURL request to the private IP address (they're both in the same subnet).
However when I make the call from the React application, the POST request URL is prefixed with the remote URL which causes the API call to fail.
The request URL is meant to be http://10.11.1.147/login
It works fine when running both applications on localhost. The API framework is implemented using Axios and React-Query.
Here is the query function performing the POST request (and I've confirmed that REACT_APP_SERVER_URL is the private IP address)
export const postLogin = async ({ email, password }) => {
let response;
const cookies = new Cookies();
try {
response = await axios.post(`${process.env.REACT_APP_SERVER_URL}/login`, {
email: email,
password: password,
});
cookies.set("JWT", response.data.jwt, { path: "/" });
cookies.set("UserId", response.data.userId, { path: "/" });
} catch (err) {
return err.response
}
};