gpt4 book ai didi

javascript - 当我使用 postman 时,console.log() 不起作用

转载 作者:行者123 更新时间:2023-12-01 16:19:02 25 4
gpt4 key购买 nike

我有一个我试图调试的函数,因为我遇到了一个错误。我已经解决了这个问题,因为我发现有人有类似的问题,但是能够通过控制台记录 JwtStrategy 中的一个参数会真的很有帮助,让我更好地理解正在传递的内容。即使其他人已经能够使用 Postman 和他们的源代码,我似乎仍然无法控制它。

所以我有 mongod 和 nodemon 在后面运行。我这就是功能。

module.exports = function(passport){

let opts = {}; //options is an object literal containing options to control how token is extracted.
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt")
opts.secretOrKey = config.secret; //string containing the secret or pem encoded public key verifying the tokens signiture
passport.use(new JwtStrategy(opts, (jwt_payload,done)=>{
console.log(jwt_payload);
User.getUserById(jwt_payload._doc._id, (err, user)=>{
if(err){
return done(err,false);
}
if(user){
return done(null, user);
}else{
return done(null,done);
}
});
}));
}

如您所见,我有一个 console.log(jwt_payload);
这就是我放入 Postman 的内容
发布方法, http://localhost:3000/users/authenticate,正文:
{
"username":"bobdylan",
"password":"123456"
}

正如我上面所说,它正在工作并返回我想要的正确 JSON。唯一的问题是这个 jwt_payload 不是控制台登录终端,所以我可以看到它通过。我在终端有这个。
Server started on port 3000
yay i am connected to databasemongodb://localhost:27017/authapp

所以“是的,我已连接”是 app.js 中的 console.log。为什么这是打印但不是我上面的console.log?我希望有这种能力来解决 future 的调试问题。

这是显示它实际工作但控制台日志不工作的附加代码
{
"sucess": true,
"token": "JWTeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTk2M2VmMGM3MjM4NjA0MGUwYTgwZjEiLCJuYW1lIjoiYm9iIiwiZW1haWwiOiJib2JAZHlsYW4uY29tIiwidXNlcm5hbWUiOiJib2JkeWxhbiIsInBhc3N3b3JkIjoiJDJhJDEwJHprbFBVWjI5dlJMLjRJWnlOZ1N6amVaMk1mVGVzcWdRSHIuTEkzVjhmZTIwT1NxT2p0STdLIiwiX192IjowLCJpYXQiOjE1MTk3OTk0NTcsImV4cCI6MTUyMDM5OTQ1N30.DlwzJuQayQ1zc4p8Gy5PGaE22N8ekyrBrmOhVPMkJ6Y",
"user": {
"id": "5a963ef0c72386040e0a80f1",
"name": "bob",
"username": "bobdylan",
"email": "bob@dylan.com"
}
}

这就是请求之后的响应。

最佳答案

对于任何为 console.log 的输出而苦苦挣扎的人, console.info等在 Postman
您可以在菜单 View >> Show Postman Console 上查看 postman 控制台

不在菜单上查看 >> 开发人员 >> 显示 DevTools

Open Postman Console to see output of console.log, console.info, etc.

关于javascript - 当我使用 postman 时,console.log() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49023050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com