Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

my app is taking localhost:3000 as the server. but i have localhost:4000 as the server

My problem is that iam using axios to communicate with backend.axios had done perfect job till now. but when i wrote a code for register, my console says that
POST http://localhost:3000/api/v1/register 500 (Internal Server Error)

so till now it responded very good.but now it thrwing an error like this.

userAction.js :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export const register = (userData) => async (dispatch) => {
  try {
    dispatch({ type: REGISTER_USER_REQUEST });

    const config = { headers: { "Content-Type": "multipart/form-data" } };

    const { data } = await axios.post("/api/v1/register", userData, config);

    dispatch({ type: REGISTER_USER_SUCCESS, payload: data.user });
  } catch (error) {
    dispatch({
      type: REGISTER_USER_FAIL,
      payload: error.response.data.message,
    });
  }
};

iam using localhost:4000 as server. but it showing me localhost:3000 which means my app url

enter image description here

>Solution :

Because you did not specify the host in your post url.Then it may be work.

/api/v1/register => http://localhost/api/v1/register

The if you have cors issue add this to the nodejs backend app.js file (as you using nodejs):

const cors = require('cors');

app.use(cors())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading