[英]How can we identify and authenticate platform requests (web, android, ios) on the node.js server using APIs?
I am developing the backend on the Nodejs server using MySQL DB.我正在使用 MySQL DB 在 Nodejs 服务器上开发后端。 I want to confirm from which device or platform as mentioned (web android or IOS) the req is coming, specifically through headers?
我想确认 req 来自提到的哪个设备或平台(web android 或 IOS),特别是通过标题? I really don't want to give access to miscellaneous requests to be authenticated.
我真的不想授予对要进行身份验证的杂项请求的访问权限。 Is there any module that identifies the platform/device??
是否有任何模块可以识别平台/设备?
PS I'm using the express framework. PS 我正在使用 express 框架。
Hi you can use npm i express-useragent
package.您好,您可以使用
npm i express-useragent
package。 It will send you below data它将向您发送以下数据
var express = require('express');
var app = express();
var useragent = require('express-useragent');
app.use(useragent.express());
app.get('/', function(req, res){
res.send(req.useragent);
});
app.listen(3000);
// Output
{
"isMobile":false,
"isDesktop":true,
"isBot":false,
.....
"browser":"Chrome",
"version":"17.0.963.79",
"os":"Windows 7",
"platform":"Microsoft Windows",
"source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79..."
}
You can categories accordingly.您可以相应地进行分类。 Note: If you want specific device like iOS, Android, Desktop then you should ask to send in api header data.
注意:如果您想要特定设备,如 iOS、Android、桌面,那么您应该要求发送 api Z099FB99966400F339FEFEFF 数据。 So you will get default in all apis.
因此,您将在所有 api 中获得默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.