I am using the boilerplate Next.js starter. In index.js, an instance of the express application is defined as expressApp. I am simply attempting to serve my favicon using serve-favicon and having no luck:
expressApp.use(favicon(path.join(__dirname, "static", "brand", "favicon.ico")));
Checked the path that is being resolved and it is correct. How does next.js implementation of express differ?
From the serve-favicon repository:
Note This module is exclusively for serving the "default, implicit favicon", which is
GET /favicon.ico. For additional vendor-specific icons that require HTML markup, additional middleware is required to serve the relevant files, for example serve-static.
So it's not possible with this package to serve a favicon in another path, because that would require adding markup. To fix this, add a link tag inside your pages/_document.js template:
<Head>
<link rel="icon" type="image/x-icon" href="/brand/favicon.ico" />
</Head>
While keeping your serve-favicon code in the index.js file:
expressApp.use(favicon(path.join(__dirname, "static", "brand", "favicon.ico")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With