I’m developing a React application with Vite and implementing user registration functionality.The goal is to send a POST request using Axios to an Express server running on localhost:8800.
However I encounter a 404 Not Found error when making the POST request for user registration.
The error occurs even though the server is running and the endpoint seems correctly defined.
import axios from "axios"
const Register = () => {
const [inputs, setInputs] = useState({
username:"",
email:"",
password:"",
})
const handleChange = e => {
setInputs(prev=>({...prev, [e.target.name]: e.target.value}))
}
const handleSubmit = async e =>{
e.preventDefault()
try{
const res = await axios.post("http:localhost:8800/auth/register", inputs)
console.log(res)
}catch(err){
console.log(err)
}
}
///
}
export default Register;
I’ve checked the server URL and confirmed that the Express server is running on the specified port.
I’ve also verified that the /register route is correctly set up in my Express app.
app.use("/server/auth", authRoutes)
I tried adding the proxy vite.config.js file but still no luck
What could be the reason for receiving a 404 error on a POST request to localhost:8800 for user registration, and how can I resolve it?
Are there specific configurations in Vite or Express that I might be missing for handling such requests?
here is my full error message
//
localhost:8800/server/auth/register:1
Failed to load resource: the server responded with a status of 404 (Not Found)
Register.jsx:22
AxiosError
code
:
“ERR_BAD_REQUEST”
config
:
{transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
message
:
“Request failed with status code 404”
name
:
“AxiosError”
request
:
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response
:
{data: ”, status: 404, statusText: ‘Not Found’, headers: AxiosHeaders, config: {…}, …}
stack
:
“AxiosError: Request failed with status code 404n at settle (http://localhost:5173/node_modules/.vite/deps/axios.js?v=afb224e6:1204:12)n at XMLHttpRequest.onloadend (http://localhost:5173/node_modules/.vite/deps/axios.js?v=afb224e6:1421:7)”
[[Prototype]]
:
Error



