This is the function I have on the back end using express:
// Function to register a new user
exports.register_user = function(req, res) {
var portalID = req.body.portalID;
var companyName = req.body.companyName;
var password = req.body.password;
var password2 = req.body.password2;
var salt = bcrypt.genSaltSync(12);
var hash = bcrypt.hashSync(password, salt);
password = hash;
var params = {
TableName: "HouseAccounts",
Item: {
"portalID": portalID,
"companyName": companyName,
"points": 0,
"password": password,
}
}
res.sendStatus(200);
}
And this is the fetch function on the front end:
function register() {
fetch("MyURL/register", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"portalID": document.getElementById("portal-id").value,
"companyName": document.getElementById("company-name").value,
"password": document.getElementById("password").value,
"password2": document.getElementById("password2").value
})
}).then(function(response){console.log(response)});
}
While I can receive the JSON data sent through the POST request on the express side and process it, unfortunately, on the front end, I am not getting any response from the back end. The connection times out with a status of (failed)
and an error message
Uncaught (in promise) TypeError: Failed to fetch
in console.