脚本移动到其他服务器时出错.
(node:15707)[DEP0005] DeprecationWarning:由于安全性和可用性问题,不推荐使用Buffer().请改用Buffer.alloc(),Buffer.allocUnsafe()或Buffer.from()方法.
当前版本:
Ubuntu 16.04.4 LTS
Node - v10.9.0
NPM - 6.2.0
Run Code Online (Sandbox Code Playgroud)
上一版本:
Ubuntu 14.04.3 LTS
NPM - 3.10.10
Node - v6.10.3
Run Code Online (Sandbox Code Playgroud)
exports.basicAuthentication = function (req, res, next) {
console.log("basicAuthentication");
if (!req.headers.authorization) {
return res.status(401).send({
message: "Unauthorised access"
});
}
var auth = req.headers.authorization;
var baseAuth = auth.replace("Basic", "");
baseAuth = baseAuth.trim();
var userPasswordString = new Buffer(baseAuth, 'base64').toString('ascii');
var credentials = userPasswordString.split(':');
var username = credentials[0] !== undefined ? credentials[0] : '';
var password = credentials[1] !== undefined ? credentials[1] : '';
var userQuery = {mobilenumber: username, otp: password};
console.log(userQuery);
User.findOne(userQuery).exec(function (err, userinfo) {
if (err || !userinfo) {
return res.status(401).send({
message: "Unauthorised access"
});
} else {
req.user = userinfo;
next();
}
});
}
Run Code Online (Sandbox Code Playgroud)
Neb*_*pic 177
new Buffer(number) // Old
Buffer.alloc(number) // New
Run Code Online (Sandbox Code Playgroud)
new Buffer(string) // Old
Buffer.from(string) // New
Run Code Online (Sandbox Code Playgroud)
new Buffer(string, encoding) // Old
Buffer.from(string, encoding) // New
Run Code Online (Sandbox Code Playgroud)
new Buffer(...arguments) // Old
Buffer.from(...arguments) // New
Run Code Online (Sandbox Code Playgroud)
请注意,Buffer.alloc()在当前Node.js版本上的速度也比新的Buffer(size).fill(0)快,这是您需要确保零填充的原因.
Vib*_*ube 18
var userPasswordString = new Buffer(baseAuth, 'base64').toString('ascii');
Run Code Online (Sandbox Code Playgroud)
将此行从您的代码更改为 -
var userPasswordString = Buffer.from(baseAuth, 'base64').toString('ascii');
Run Code Online (Sandbox Code Playgroud)
或者就我而言,我以相反的顺序给出了编码
var userPasswordString = Buffer.from(baseAuth, 'utf-8').toString('base64');
Run Code Online (Sandbox Code Playgroud)
iLu*_*gix 14
使用不推荐使用的new Buffer()构造函数(Yarn使用的iE)会导致不推荐使用警告。因此,不应使用不建议使用的/不安全的Buffer构造函数。
根据弃用警告,new Buffer()应替换为以下之一:
Buffer.alloc() Buffer.allocUnsafe() 要么 Buffer.from()为了避免此问题,另一种选择是改为使用安全缓冲区包。
您也可以尝试(使用纱线时..):
yarn global add yarn
Run Code Online (Sandbox Code Playgroud)
如此处所述:链接
| 归档时间: |
|
| 查看次数: |
48039 次 |
| 最近记录: |