node.js页面两次刷新调用资源? [英] node.js page refresh calling resources twice?
问题描述
我有一个基本的node.js设置,但是我想我缺少一些东西.
I have a basic node.js setup, but I think I'm missing something.
我的main.js
:
var a = require('./another.js');
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200,
{
'Content-Type': 'text/html'
});
response.write(a.saysomething('Hi there!') + '<br />');
response.end();
}).listen(27182);
console.log('Server running at http://127.0.0.1:27182/');
我的another.js
:
exports.saysomething = function (str) {
console.log('in saysomething!');
return str + ' hey there!';
}
问题是我的控制台两次输出in saysomething!
.我想念什么吗?刷新页面时,我只希望有一个in saysomething!
.
The issue is that my console is outputting in saysomething!
twice. Am I missing something? When I refresh the page, I expect only one in saysomething!
.
推荐答案
您的浏览器可能除了试图输入的URL之外,还尝试获取favicon.ico.尝试仅在命令行上执行以下命令:curl http://127.0.0.1:27182/
Your browser is likely trying to get favicon.ico in addition to the url you are hitting. Try to just do the command on the command line: curl http://127.0.0.1:27182/
此外,您可以为request.url
添加日志记录.这将向您显示正在请求哪些URL.
Also, you can add logging for request.url
. That will show you which urls are being requested.
这篇关于node.js页面两次刷新调用资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!