favicon.ico导致报错
var http = require("http");
var url = require("url");
function start(route,handle){
function onRequest (request,response){
var pathname = url.parse(request.url).pathname;
var content;
var postdata;
console.log(pathname);
response.writeHead(200,{"Content-Type":"text/html"});
request.setEncoding("utf8");
request.addListener("data",function(Chunk){
postdata += postDataChunk;
});
request.addListener("end",function(){
console.log("received post data end");
content = route(handle,pathname);
});
response.write(content);
response.end();
}
http.createServer(onRequest).listen(8080);
}
exports.start = start;
我代码是这样的,报错
throw new TypeError('first argument must be a string or Buffer');
貌似是由于浏览器请求的 /favicon.ico
导致错误,请问怎么解决呀
4 回复
怎么解决呢?
很简单,如果检测到url为/favicon.ico,则直接response.end();
look the framework : https://github.com/brighthas/stuwebfk
at /lib
dir source.
签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3