没有得到正确的URLpath – URLpath是:/favicon.ico

我使用下面的代码,当我第一次在浏览器中运行一些path像http://localhost:9000/aaaa/bbbb/cccc

在第一次Im得到/ aaaa / bbb / cccc但在第二我得到的URLpath是:/favicon.ico

我能做些什么来克服这个问题?

  url = require('url'); .... http.createServer(function(req, res) { var hostname = req.headers.host.split(":")[0]; var pathname = url.parse(req.url).pathname; console.log("Host name: " + hostname); console.log("URL path is: " + pathname); 

  1. 如果你有nginx在节点前面,添加location = /favicon.ico { access_log off; log_not_found off; } location = /favicon.ico { access_log off; log_not_found off; } location = /favicon.ico { access_log off; log_not_found off; }到conf。
  2. 从节点服务

     if (req.url === '/favicon.ico') { res.writeHead(200, {'Content-Type': 'image/x-icon'} ); return res.end(); } 
  3. 像Quentinbuild议的那样,把html中的图标链接起来。

停止浏览器从默认位置请求collections夹图标的唯一方法是在所提供的HTML文档中为其指定明确的位置。

 <link rel="shortcut icon" href="URL HERE">