Node. js favicon. ico request troubleshooting, node. jsfavicon. ico
Copy codeThe Code 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 during the request:
In the first example, the URL address is the target URL of the client request entered by the user. "/" indicates that the target url address is the root directory of the web application.
The second target URL address is the display icon of the page in the favorites folder. The default value is favicon. ico. The target URL address of the automatically sent request.
You can modify the preceding code to block such requests.
Copy codeThe Code 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 simple, but practical. Let's record it.