I want to make MERN project.I uses Redux Toolkit for state management. I will use authentication in my project but I got error while requesting server that is written myself.error is network error and net::ERR_NAME_NOT_RESOLVED and also you can see this link https://resimlink.com/9tbn2DZJNmR thanks for help
I wrote this code for request to server.
import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from 'axios';
const backendUrl = 'http://176.232.58.54:5000';
export const registerUser = createAsyncThunk('register', async(userData)=>{
try{
const config = {
headers: {
'Content-Type': 'application/json',
},
}
const response= await axios.post(`http://176.232.58.54
:5000/register`,userData,config)
return response.data;
}
catch(error){
console.error(error.message)
}
})
const express= require('express');
const app= express();
const database= require('./config/database.js');
const bodyParser = require('body-parser');
const cors= require('cors')
const dotenv = require('dotenv');
const authRoute= require('./routes/auth.js')
dotenv.config()
app.use(cors());
//app.use(bodyParser.json({limit:'50mb',extended:true}));
app.use(express.json({limit:'50mb',extended:true}));
database();
app.use('/',authRoute)
const PORT= process.env.PORT || 5000
app.listen(PORT,()=>{
console.log('Server is running on '+ PORT)
})
I don't see a /register endpoint in your server, only / so your request to
http://176.232.58.54:5000/registerwould never be found.Try
http://176.232.58.54:5000Also another quick side note is that you can set a default baseurl for axios. By doing so you won't need to repeat the ip everywhere