My website transfers data through JSON objects using Angular's $http post.
If you'd like to see the console logs and responses, visit my website:
Initially, I used x-form-urlencoded encoding successfully and decided to switch to application/json as I plan to push the data to MongoDB in the future.
While simple objects work well with req.body.___, more complex JSON objects and arrays are not functioning properly. Additionally, I am encountering a gateway timeout (504) error in response, though emails are being sent without issues via Amazon SES.
Below is an example of my HTML email code. I have tried various modifications but all result in 'undefined'. Despite this, console.log confirms that the data is being transmitted correctly.
replyTo: req.body.user[0].email,
subject: 'Clean Path Contact from '+ req.body.user.fname + ' '+ req.body[0].user.phone, // REQUIRED.
text: req.body.user + '\n' + '\n' + 'Customer Name address: ' + req.body.user.fname[0] + '\n' + 'Customer email address: ' + req.body.user[0].email + '\n' +'Customer Phone Number: ' + req.body.user[0].phone,
};
This is an example of how my typical objects are structured:
{ user: {[
{
"fName":"",
"lName":"",
},
{
"name": "roomsclean1",
"price": 27,
"title": "Room(s) to clean",
}, {
"name": "roomsprotect1 ",
"price": 62,
}
]}
Alternatively, I sometimes use an array of objects like [{username: jim, lname: thomas}], yet req.body[0].username returns undefined.
In contrast, simpler objects like {username: jim, lastname: thomas} work seamlessly, and the email successfully receives the data.