【发布时间】:2014-01-25 22:28:38
【问题描述】:
我正在尝试使用 Connect 创建中间件,该中间件将 Hello World 显示到网页并将其记录在控制台中。我已经能够让它在我的浏览器中工作,但我注意到控制台记录了两次 - 使用 curl 时它不会这样做。我没有网站图标,Chrome 中的所有扩展都被禁用。
这是我的代码...相当简单:
var connect = require('connect');
var app = connect();
app.use(function (req, res, next) {
console.log('hello world');
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
app.listen(5000);
同样,在 Chrome 中打开 http://localhost:5000 后,这是终端中的输出:
hello world
hello world
为什么会被调用两次?这正常吗?
【问题讨论】:
标签: node.js http request connect