reactjs - Backend not receiving request sent from frontend - Stack Overflow

admin2025-04-27  3

I've been trying to post a request to my Express backend using axios (I'm new to using axios, so forgive my ignorance here). I've got my backend endpoint running locally as shown:

app.post('/sign-up', jsonParser, async (req: Request, res: Response) => {
console.log("Received POST request:", req.method, req.url);
console.log("Request body:", req.body);
const newUser = await prisma.user.create({data: req.body});
console.log("Created new user:", newUser);
res.status(200).json(newUser);
});

I am trying to send a request to it from my frontend as shown:

const handleSignUp = async () => {
console.log("Username: ", username);
console.log("Email: ", email);
console.log("Password: ", password);
axios("http://localhost:5000/sign-up", {
    method: 'POST',
    headers: { "Content-Type": "application/json" },
    data: JSON.stringify({ username, email, password }),
  })
  .then((response) => console.log(response))
  .catch((err) => console.log(err));
};

I'm not sure what I'm doing wrong here. In my network tab, I see the status as "Pending":

I have tried sending a request using Postman and it has worked, but the issue only arrises when I try doing so from my React front end. Anyone has any ideas?

转载请注明原文地址:http://anycun.com/QandA/1745706563a91094.html