我在快速方面有这个功能:
// Register user login
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);
}
前端的这个抓取:
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)});
}
在快速方面,我可以收到通过POST发送的JSON,并对该数据进行处理。但是,在我的前端,我没有收到快递方的回复。连接超时且状态为(failed)
,控制台中出现错误Uncaught (in promise) TypeError: Failed to fetch
。
答案 0 :(得分:0)
好的,问题是我正在使用AWS Cloud9和我的公共IP来访问重新启动实例时更改的API,因此请求根本没有到达服务器端。