title: 404 error when trying to post to api route
body: <p>I am trying to implement authentication into my react app and I am recieving a 404 error whenever I try to POST to one of my express API routes while deployed. The server that I am deploying throus is AWS EC2 if it makes a difference.</p>
  
  <p>Here is my Server.js file:</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const bodyParser = require('body-parser');
  const mongoose = require('mongoose');
  const passport = require('passport');
  const cors = require('cors');
  
  const users = require('./routes/api/users');
  
  const app = express();
  
  app.use(cors());
  
  // Bodyparser Middleware
  app.use(
    bodyParser.urlencoded({
      extended: false
    })
  );
  app.use(bodyParser.json());
  
  // DB Config
  const db = require('./config/keys').mongoURI;
  
  // Connect to MongoDB
  mongoose
    .connect(
      db,
        { useNewUrlParser: true, useUnifiedTopology: true } 
    )
    .then(() =&gt; console.log("MongoDB successfully connected"))
    .catch(err =&gt; console.log(err));
  
  // Passport middleware
  app.use(passport.initialize());
  
  // Passport config
  require('./config/passport')(passport);
  
  // Routes
  app.use('/api/users', users)
  
  // Serve static assets if in production
  if (process.env.NODE_ENV === 'production') {
  
    // Set static folder
    app.use(express.static('client/build'));
  
    app.get('*', (req, res) =&gt; {
      res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
    });
  }
  
  const port = process.env.PORT || 5000;
  
  app.listen(port, () =&gt; console.log(`Server started on port ${port}`));
  </code></pre>
  
  <p>My ./routes/api/users.js file:</p>
  
  <pre><code>const express = require("express");
  const router = express.Router();
  const bcrypt = require("bcryptjs");
  const jwt = require("jsonwebtoken");
  const keys = require("../../config/keys");
  
  // Load input validation
  const validateRegisterInput = require("../../validation/register");
  const validateLoginInput = require("../../validation/login");
  
  // Load User model
  const User = require("../../models/User");
  
  // @route POST api/users/register
  // @desc Register user
  // @access Public
  router.post("/register", (req, res) =&gt; {
      // Form validation
  
    const { errors, isValid } = validateRegisterInput(req.body);
  
    // Check validation
      if (!isValid) {
        return res.status(400).json(errors);
      }
  
    User.findOne({ email: req.body.email }).then(user =&gt; {
        if (user) {
          return res.status(400).json({ email: "Email already exists" });
        } else {
          const newUser = new User({
            name: req.body.name,
            email: req.body.email,
            password: req.body.password
          });
  
    // Hash password before saving in database
          bcrypt.genSalt(10, (err, salt) =&gt; {
            bcrypt.hash(newUser.password, salt, (err, hash) =&gt; {
              if (err) throw err;
              newUser.password = hash;
              newUser
                .save()
                .then(user =&gt; res.json(user))
                .catch(err =&gt; console.log(err));
            });
          });
        }
      });
    });
  
    // @route POST api/users/login
  // @desc Login user and return JWT token
  // @access Public
  router.post("/login", (req, res) =&gt; {
      // Form validation
  
    const { errors, isValid } = validateLoginInput(req.body);
  
    // Check validation
      if (!isValid) {
        return res.status(400).json(errors);
      }
  
      const email = req.body.email;
      const password = req.body.password;
  
    // Find user by email
      User.findOne({ email }).then(user =&gt; {
        // Check if user exists
        if (!user) {
          return res.status(404).json({ emailnotfound: "Email not found" });
        }
  
    // Check password
        bcrypt.compare(password, user.password).then(isMatch =&gt; {
          if (isMatch) {
            // User matched
            // Create JWT Payload
            const payload = {
              id: user.id,
              name: user.name
            };
  
    // Sign token
            jwt.sign(
              payload,
              keys.secretOrKey,
              {
                expiresIn: 31556926 // 1 year in seconds
              },
              (err, token) =&gt; {
                res.json({
                  success: true,
                  token: "Bearer " + token
                });
              }
            );
          } else {
            return res
              .status(400)
              .json({ passwordincorrect: "Password incorrect" });
          }
        });
      });
    });
  
    module.exports = router;
  </code></pre>
  
  <p>Here is an example of one of my calls made to the express api:</p>
  
  <pre><code>// Register User
  export const registerUser = (userData, history) =&gt; dispatch =&gt; {
    axios
      .post("http://localhost:5000/api/users/register", userData)
      .then(res =&gt; history.push("/login")) // re-direct to login on successful register
      .catch(err =&gt;
        dispatch({
          type: GET_ERRORS,
          payload: err.response.data
        })
      );
  };
  </code></pre>
  
  <p>When I submit my form when I deploy to my server I get this error: </p>
  
  <blockquote>
    <p>POST <a href="https://domainname.net/api/users/register" rel="nofollow noreferrer">https://domainname.net/api/users/register</a> 404 (Not Found)</p>
  </blockquote>
  
  <p>I am running my front end on port 3000 and my api server on port 5000. All of my code works locally, and I have no idea what's happening when I deploy to my ec2 server.</p>