自我提升之node.js--/favicon.ico请求次数
问题描述:自我学习node.js时,在学习模块内容(相当于java中的类)时,发现发送了两次请求,觉得很奇怪。代码如下
var http = require('http');
var User = require("./class/UserClass");
http.createServer(function(request,response){
response.writeHead(200,{'Content-type':'text/html;charset=utf-8'});
if(request.url!=="/favcion.ico"){
user = new User();
user.id=1;
user.name="mode.js";
user.play(response);
response.end('');
}
}).listen(8000);
console.log("Server running in port 8000");
UserClass.js文件
function User(){
this.id;
this.name;
this.play=function(response){
response.write("my name is "+this.name);
console.log("my name is "+this.name);
}
}
module.exports=User;
运行的时候后台console.log一直打印两次
自己百度了一下才发现node.js的每个页面默认都会再发一个/favicon.ico
将这个请求打印出来会分别打印
Server running... 1 '/' 2 '/favicon.ico'
但是我明明已经过滤了该请求,为什么还是两次呢。仔细检查了一下才发现自己单词写错了把favicon写成了favcion。太尴尬了。。。。