I'm trying to create a contact form in my react app. Every time I submit the form my Express server only receives the parameters that are empty.
Here is my server side code:
app.use(express.json());
router.post("/contact", (req, res) => {
console.log(req.body); // prints {name: "", subject: ""}
res.status(200).send("Success");
});
My axios request:
axios.post(
`http://localhost:9000/.netlify/functions/api/contact`,
{
name: name,
emailAddress: email,
subject: subject,
message: message,
},
{
headers: {
"Content-Type": "application/json",
},
}
);
It only prints prints {name: "", subject: ""}
but I am filling out email address and message fields as well.
I have tried using bodyParser but it gives me deprecation notice as I am using Express 4.17.1.
What am I doing wrong?