Node. js favicon. ico request troubleshooting, node. jsfavicon. ico

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.