Answer the question
In order to leave comments, you need to log in
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
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')));
// static foulder
app.use(statics(path.join(__dirname, 'public')));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question