在node.js中删除请求表达

Jus*_*tin 8 javascript node.js express

是否可以使用Node.js和express来删除某个路由的请求?IE不返回http状态或任何标题?我想关闭连接.

app.get('/drop', function(req, res) {
    //how to drop the request here
});
Run Code Online (Sandbox Code Playgroud)

Don*_*Don -2

是的你可以。您所需要做的就是调用 res.end 方法(可选)传入状态代码。

使用以下方法之一:

res.end();
res.status(404).end();
Run Code Online (Sandbox Code Playgroud)

如果您还想设置标题,那么您可以使用 res.set 方法。见下文

res.set('Content-Type', 'text/plain');

res.set({
  'Content-Type': 'text/plain',
  'Content-Length': '123',
  'ETag': '12345'
})
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请查看这里 http://expressjs.com/api.html