如何获得 Node.js 请求类型?
How do I get Node.js request type?
我试图弄清楚如何从节点请求中获取请求类型。我想根据类型执行不同的任务。
module.exports = function(req, resp, next){
if (req.type == 'GET'){
//Do something
}else{
// Do else something
}
}
req.method
returns 使用的请求 HTTP 方法。
app.use('/', (req, res, next) => {
let requestMethod = req.method;
console.log(requestMethod);
res.send('ok');
});
你可以查看这个示例代码
exports.permissionsCheck = async (req, res, next) => {
const userId = req.body.auth.id;
let permissions = await PermissionsClass.getAllPermissions(userId)
let url = req.url
let method = req.method
console.log(method)
return next();
};
我试图弄清楚如何从节点请求中获取请求类型。我想根据类型执行不同的任务。
module.exports = function(req, resp, next){
if (req.type == 'GET'){
//Do something
}else{
// Do else something
}
}
req.method
returns 使用的请求 HTTP 方法。
app.use('/', (req, res, next) => {
let requestMethod = req.method;
console.log(requestMethod);
res.send('ok');
});
你可以查看这个示例代码
exports.permissionsCheck = async (req, res, next) => {
const userId = req.body.auth.id;
let permissions = await PermissionsClass.getAllPermissions(userId)
let url = req.url
let method = req.method
console.log(method)
return next();
};