문제

Checking the simple code

var http  = require('http');
var server = http.createServer(function(req, res){
    console.log("Got Request");
    res.end("");
});

When I am sending request to server using Firefox 8.0.1, I am geting console output once

Got Request

Using Chrome 16.0

Got Request
Got Request

why createServer is running 2 times on chrome??? is it a bug or something wrong with my code?

도움이 되었습니까?

해결책

Browsers may submit addtional requests to the site, in which the most notable one is favicon.ico. Its purpose is to get the favicon for the site. And some plugins will also make additional requests. To make clear exactly what is being requested, you may print the url for the requests:

var http  = require('http');
var server = http.createServer(function(req, res){
    console.log(req.url); // <<<<<<<<<<<<<<<<<<<<<<<<<<<< print the requested url
    res.end("");
});
server.listen(8000)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top