为什么node.js,http-server,显示有两个请求?
我有以下简单的HTTP服务器设置使用node.js:
var http = require('http'); var port = 12311 http.createServer(function (req, res) { console.log("Incomming request from " + req.connection.remoteAddress); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end("test string"); }).listen(port); console.log("Listening on " + port);
正如你所看到的,当请求进入时,我将它logging到控制台。 现在,当我浏览到localhost:12311
控制台显示有两个连接进来:
"E:\Program Files\nodejs\node.exe" hello-world-server.js Listening on 12311 Incomming request from 127.0.0.1 Incomming request from 127.0.0.1
为什么是这样?
这通常是favicon.ico
的请求。 即使你没有,你也可以根据标准定义一个默认的文件path,如果你没有在标题中设置相关的<link rel="shortcut icon"...
。
find这些请求的最佳方法是:
- 客户端,通过打开开发人员工具并查看networking选项卡。
- 服务器端,通过logging
req.url