Nodejs web server calling requestListener twice when page is loaded

后端 未结 2 807
一整个雨季
一整个雨季 2020-12-30 03:52

The following is the example web server from the documentation, with an added counter. It prints the counter to the console whenever a client/browser requests the page.

2条回答
  •  一向
    一向 (楼主)
    2020-12-30 04:48

    We can ignore the page refresh count due to favicon with the following code snippet:

    if (request.url === '/favicon.ico') {
       response.writeHead(200, {'Content-Type': 'image/x-icon'} );
       response.end();
       console.log('favicon requested');
       return;
    }
    

    Ref: https://gist.github.com/763822

提交回复
热议问题