我想使用一个名为token的字段发布一个请求。这是我的mongoose模式
const UserSchema = mongoose.Schema({
name: {
type: String
},
email: {
type: String,
required: true,
unique: true
},
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
phone: {
type: String
},
resetPasswordToken: {
type: String
},
resetPasswordExpires: {
type: Date
}
});这是我来自user.js的路径文件
router.put('/reset/:token', function(req, res) {
console.log('listening');
User.findOneAndUpdate(
{resetPasswordToken:req.params.token},
{
password: req.body.password,
resetPasswordToken: undefined,
resetPasswordExpires: undefined
},
function(err,user) {
if(err) {
console.log(err + 'is here');
} else {
res.json(user);
}
}
);
});这就是我发送` `POST请求的地方。
resetPassword(passwordData) {
let headers = new Headers();
console.log(passwordData);
headers.append('Content-Type','application/json');
return this.http.put('http://localhost:3000/api/reset/'+passwordData.token,passwordData,{headers: headers})
.map(res => res.json());
}未执行任何操作我无法在cmd中看到listening。对于用户,我已经将令牌值设置为
"resetPasswordToken" : "2a287acacf7d5e98de9a158c8be82744ef0302f9"我可以使用postman进行更新,但无法使用代码进行更新。
发布于 2018-07-14 23:04:33
如果您能够通过邮递员而不是客户来处理请求,则有两种可能性:
app.use((req,res,next)=>{ res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE"); next() })
之前在客户端或服务器中发送时完成
https://stackoverflow.com/questions/51340039
复制相似问题