Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 370
tedyyu Avatar asked Apr 29 '14 06:04

tedyyu


2 Answers

What i did to update the favicon is put a version behind it.

<link rel="icon" href="/img/icon_fav.png?version=2" type="image/png">
like image 80
DenLanden Avatar answered Nov 08 '22 06:11

DenLanden


Put icon in root folder and use:

<link rel="icon" href="favicon.ico" type="image/x-icon">
like image 2
Joakim M Avatar answered Nov 08 '22 07:11

Joakim M