nodejs过滤favicon请求

const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  if(req.url!='/favicon.ico'){                        //过滤favicon请求
  console.log('request received!');
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  var name='rod johnson';
  res.end(`Hello
  ${name}`);
 }
}
);

server.listen(port, hostname, () => {
console.log(`服务运行于: http://${hostname}:${port}/`);
});

posted @ 2017-05-18 10:51  conserdao  阅读(1144)  评论(0编辑  收藏  举报