The code copy is as follows:
var http=require("http");
var server=http.createServer();
server.on("request",function(req,res){5 console.log(req.url);
res.end();
});
server.listen(1337,"127.0.0.1");
Such code will have two requests when requesting:
In the first article, the URL address is the target URL address requested by the client entered by the user, and "/" means that the target URL address of the user is the root directory of the web application.
The second target URL address asks the browser to display the icon of the page in the favorites. The default is favicon.ico. The destination URL address of the request automatically issued by the request.
You can modify the above code and block such requests
The code copy is as follows:
var http=require("http");
var server=http.createServer();
server.on("request",function(req,res){
if(req.url!=="/favicon.ico")
console.log(req.url);
res.end();
});
The solution is very simple, but it is very practical. Please record it.