'POST to backend is returning a 404. (React => Express)

I've made a fairly simple register/login form for my backend to save to a database. It was working a couple days ago, and now nothing. When I make the fetch call the payload is filled out appropriately. My terminal tells me 'POST /api/v1/users/register 404 13.504 ms - 161'. My fetch request looks like:

        const handleRegisterSubmit = async (e) => {
         e.preventDefault()
         await fetch('http://localhost:3333/api/v1/users/register', {
          method: 'POST',
          mode: 'cors',
          headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
          },
          body: JSON.stringify({
            dealershipname: registerForm.dealershipname,
            password: registerForm.password,
            streetadress: registerForm.streetadress,
            city: registerForm.city,
            state: registerForm.state,
            zip: registerForm.zip,
            phone: registerForm.phone,
            email: registerForm.email
           })
         })
        .then(res => res.json())
        .then(data => {
            if (data.error) {
                setError(data.error)
            } else {
                navigate('/porsche')
            }
        })
}

My backend route looks like:

    router.post('/register', async (req, res) => {
    // check for username and password on req
   if (!req.body.dealershipname || !req.body.password) {
     return res.status(400).json({
       error: 'Please include username and password'
     })
   }

  // check database for existing user 
  const user = await models.User.findOne({
    where: {
     dealershipname: req.body.dealershipname
    }
  })
 // if exists, send error
 if (user) {
   return res.json(400).json({
     error: 'Username already in use. Pick another'
   })
  }
// hash password
const hash = await bcrypt.hash(req.body.password, 10)
// create user
const newUser = await models.User.create({
   dealershipname: req.body.dealershipname,
   password: hash,
   streetadress: req.body.streetadress,
   city: req.body.city,
   state: req.body.state,
   zip: Number(req.body.zip),
   phone: Number(req.body.phone),
   email: req.body.email
  })

// respond with success message
 return res.status(201).json(newUser)
})

My server is running fine. I've set the backend port to 3333 in case that it just needed some room from the front end port. The errors I'm getting in the browser are the same thing. Any help or suggestions would be a lifesaver.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source