Refund request in node.js express

Is it possible to use Node.js and express to remove a request for a specific route? I.E. not return http status or any headers? I would just like to close the connection.

app.get('/drop', function(req, res) { //how to drop the request here }); 
+5
source share
2 answers

You can do this when you want to close the connection: res.end()

0
source

Yes, you can. All you have to do is call the res.end method, optionally pass the status code.

Use one of the following methods:

 res.end(); res.status(404).end(); 

If you want to set the headers as well, you must use the res.set method. See below

 res.set('Content-Type', 'text/plain'); res.set({ 'Content-Type': 'text/plain', 'Content-Length': '123', 'ETag': '12345' }) 

See here http://expressjs.com/api.html for more details.

-1
source

Source: https://habr.com/ru/post/1236395/


All Articles