node.js输入图片流
发布于 11 年前 作者 chinawomen 6810 次浏览 最后一次编辑是 8 年前
fs.readFile(path, function(err, buf){
      if (err) return next(err);
      icon = {
        headers: {
            'Content-Type': 'image/x-icon'
          , 'Content-Length': buf.length
          , 'ETag': '"' + utils.md5(buf) + '"'
          , 'Cache-Control': 'public, max-age=' + (maxAge / 1000)
        },
        body: buf
      };
      res.writeHead(200, icon.headers);
      res.end(icon.body);

此代码来自express 路径\node_modules\express\node_modules\connect\lib\middleware\favicon.js 刚才用express做了一个例子发现有默认ico图标,好奇了下 发现有个方法 app.use(express.favicon());是设置icon图标的

2 回复

额= =被你发现了

回到顶部