gpt4 book ai didi

node.js - 服务图标 next.js

转载 作者:搜寻专家 更新时间:2023-11-01 00:28:20 26 4
gpt4 key购买 nike

我正在使用样板 Next.js starter .在 index.js 中,express 应用程序的一个实例被定义为 expressApp。我只是尝试使用 serve-favicon 来为我的 favicon 提供服务,但没有成功:

expressApp.use(favicon(path.join(__dirname, "static", "brand", "favicon.ico")));

检查了正在解析的路径,是正确的。 express 的 next.js 实现有何不同?

最佳答案

来自serve-favicon存储库:

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.

所以这个包不可能在另一个路径中提供 favicon,因为那需要添加标记。要解决此问题,请在 pages/_document.js 模板中添加一个 link 标记:

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

同时将您的 serve-favicon 代码保存在 index.js 文件中:

expressApp.use(favicon(path.join(__dirname, "static", "brand", "favicon.ico")));

关于node.js - 服务图标 next.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49120184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com