nodejs Firefox vs Chrome (is it a bug)
-
27-10-2019 - |
문제
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)
제휴하지 않습니다 StackOverflow