首页 > 解决方案 > 未更新根 URL www.domain.com 的元标记

问题描述

我正在创建一个部署在 firebase 上的 Angular8 Universal 应用程序。引用了这个网站Angular 通用与 firebase

当我在本地使用 express 服务器运行和服务应用程序时,所有路由都加载了更新的元标记。当我在 firebase 上部署应用程序时,一切正常,但根路径上的元标记没有更新。他们在所有其他路线上都工作得很好。当我打开检查元素时,元标记也会更新。我已经添加了一些配置,用于不缓存 firebase.json 上的 html 文件如何防止 SPA 的 index.html 缓存,并将server.ts 文件中的“缓存”值设置为“无缓存”为

app.get('*', (req, res) => {
  res.set('Cache-Control', 'public, max-age=0, s-maxage=0, no-cache');
  res.render('index', { req });
});

但没有什么对我有用。请帮忙。

标签: angulargoogle-cloud-functionsangular8firebase-hostingangular-universal

解决方案


这是与 firebase 云功能相关的问题。云功能不会在根路径(www.domain.com)上被调用,因此不会在服务器端更新元标记。我通过在应用程序的根目录中创建文件夹“test”并将所有数据从 dist/browser 文件夹复制到“test”文件夹并将 index.html 文件重命名为其他文件(例如 index2.html)解决了这个问题. 还使用以下行更新了 firebase.json 文件:

....
"hosting": {
    "public": "test",
    ....

因此,每当输入 URL 时,firebase 都会搜索公共文件夹中的 index.html 文件,如果没有 index.html 文件,它将调用我们的云函数。


推荐阅读