W
W
Wasya UK2017-05-31 18:07:46
Node.js
Wasya UK, 2017-05-31 18:07:46

Why won't Node.js load the favicon?

It seems that I am doing everything right, but why then does the server find the favicon, but it is not displayed on the site? What could be wrong? Thanks in advance
Here is the code:

var express = require('express');
var favicon = require('serve-favicon');

module.exports = function() {
    var app = express();
    
    // set engine
    app.set('views', __dirname + '/views');
    app.set('view engine', 'pug');
    
    // headers
    app.use(function (req, res, next) {
        res.header("Access-Control-Allow-Origin", req.headers.origin);
        res.header('Access-Control-Allow-Credentials', 'true');
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        next();
    });
    
    // static foulder
    app.use(statics(path.join(__dirname, 'public')));
    
    //favicon
    app.use(favicon(path.join(__dirname, 'public/img/assets''favicon.ico')));
    
    return app;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Ignatenko, 2017-05-31
@lepard

Perhaps they incorrectly indicated the path in the html itself
. And if I were you, I would delete the line altogether

//favicon
    app.use(favicon(path.join(__dirname, 'public/img/assets', 'favicon.ico')));

Since with these lines you can already refer to the favicon
// static foulder
    app.use(statics(path.join(__dirname, 'public')));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question