简体   繁体   中英

How to add a custom favicon to sails.js application?

Sails.js app uses a default favicon from express. I want to replace it with my own one but have struggled with it for a couple of hours.

I have tried to add a separate favicon.js with following code under config folder, but without luck.

/**
* favicon.ico
*/
var favicon = require('static-favicon');
var path = require('path');

module.exports = {
  express: {
    customMiddleware: function(app){
      console.log('loading favicon.'); //executed
      app.use(favicon(path.join(__dirname, 'icon_fav.ico')));
      app.use(function (req, res, next) {
        console.log("installed customMiddleware is used");
        next();
      })
    }
  }

};

By the way, adding following line in the view template will work in both Chrome and Fire Fox, but not in Safari (OSX), don't know why.

<link rel="icon" href="/img/icon_fav.png" type='image/png'>

Also tried to put /favicon.ico under web server root.

Googled for this, and it seems no one asked before.
Can someone point me to a solution?

我更新favicon所做的是放在它背后的版本。

<link rel="icon" href="/img/icon_fav.png?version=2" type="image/png">

将图标放在根文件夹中并使用:

<link rel="icon" href="favicon.ico" type="image/x-icon">

sail 0.12实际上是从public / favion.ico提供的(虽然boostrapped框架存储在它的资产中,文档说它在资产/ favicon.ico

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM