我正在使用节点的http模块编写一个简单的node.js文件服务器(我没有使用EXPRESS).
我注意到我的初始GET请求正在激活,所有后续的GET请求都是针对css和javascript进行的; 但是,我没有收到关于favicon的请求.即使我查看页面检查器,我也没有任何错误,并且favicon没有显示在资源中.
HTML
// Inside the head of index.html
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<link rel="icon" href="img/favicon.ico" type="image/x-icon">
Run Code Online (Sandbox Code Playgroud)
Node.js的
http.createServer(function(req, res){
// log each req method
console.log(`${req.method} request for ${req.url}`);
}).listen(3000)
Run Code Online (Sandbox Code Playgroud)
有一个默认图标是胡子,但不是我的自定义图标.我在这里错过了什么?
以防万一与问题相关.我正在使用节点v4.2.4
编辑
我认为这与我如何阅读和提供文件有关.
if ( req.url.match(/.ico$/) ){
var icoPath = path.join(__dirname, 'public', req.url);
var fileStream = fs.createReadStream(icoPath, "BINARY");
res.writeHead(200, {"Content-Type": "image/x-icon"});
fileStream.pipe(res)
Run Code Online (Sandbox Code Playgroud)
我不应该使用读取流吗?是二进制编码还是utf-8或其他?
我觉得我在这里错过了一些东西.
Date.getDay()方法应该返回0-6之间的值.星期日为0,星期六为6.
现在我有两个日期,两个都是'星期日',应该返回0.
new Date('1990-11-11').getDay() // returns 6
new Date('2016-1-3').getDay() // returns 0
Run Code Online (Sandbox Code Playgroud)
造成这种差异的原因是什么?我敢问这个.getDay()方法的有效性,但我无法弄清楚发生了什么.
编辑
> new Date('1990-11-11')
Sat Nov 10 1990 17:00:00 GMT-0700 (MST)
> new Date('2016-01-03')
Sat Jan 02 2016 17:00:00 GMT-0700 (MST)
> new Date('2016-1-3') // they say this format is wrong, but it returns the right date
Sun Jan 03 2016 00:00:00 GMT-0700 (MST)
Run Code Online (Sandbox Code Playgroud)
我不明白发生了什么.1月3日是星期日,1990年11月11日是星期日.为什么周六说?