写个中间件,mobile.middleware.ts
import { HttpException } from "@nestjs/common";
export function judgeMobile(req, res, next) {
const deviceAgent = req.headers["user-agent"]?.toLowerCase();
const agentID = deviceAgent?.match(/(iphone|ipod|ipad|android)/);
if (agentID) {
//移动端
next();
} else {
throw new HttpException("请使用移动端访问", 500)
}
};
网友评论