Home > Web Front-end > JS Tutorial > body text

Favicon.ico request problem handling in node.js_node.js

WBOY
Release: 2016-05-16 16:26:47
Original
2601 people have browsed it

Copy code The 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 when requesting:

The first URL address is the target URL address of the client request entered by the user, and "/" means that the user's target URL address 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. And the target URL address of the automatically issued request.

You can modify the above code to block such requests

Copy code The 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 very simple but very practical, friends, please record it too.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!