0

我今天尝试 koajs 并编写 helloworld 示例:

/**
* index.js
*/
var koa = require('koa');
var app = koa();

app.use(function*(){
  this.body = 'hello world';
  console.log('success!');
});

app.listen(8080);  

然后我运行 index.js 文件并在浏览器中访问 localhost:8080,但是每次刷新页面时 console.log 似乎都会触发两次。为什么 ?

4

1 回答 1

5

在浏览器控制台中查看您的网络选项卡或在服务器上记录请求,这是对 favicon 的请求。

您可以像这样记录您的服务器请求

app.use(function*(){
  this.body = 'hello world';
  console.log(this.url);
});

您将在控制台中看到:

/
/favicon.ico
于 2014-05-08T16:11:27.350 回答