Pra*_*dya 1 firebase-hosting google-cloud-functions angular-universal angular angular8
我正在创建一个部署在 firebase 上的 Angular8 通用应用程序。引用了这个网站Angular universal with firebase
当我在本地使用 Express 服务器运行并提供应用程序时,所有路由都将加载更新的元标记。当我在 firebase 上部署应用程序时,一切正常,但根路径上的元标记没有更新。它们对于所有其他路线都工作得非常好。当我打开检查元素时,元标记也会更新。我添加了一些配置,以便不在 firebase.json How to Prevent caching for the index.html of an SPA上缓存 html 文件,并将 server.ts 文件中的“cache”值设置为“No-cache”,如下所示
app.get('*', (req, res) => {
res.set('Cache-Control', 'public, max-age=0, s-maxage=0, no-cache');
res.render('index', { req });
});
Run Code Online (Sandbox Code Playgroud)
但对我来说没有任何作用。请帮忙。
这是与firebase云功能相关的问题。云函数不会在根路径(www.domain.com)上调用,因此不会更新服务器端的元标记。我通过在应用程序的根目录中创建一个文件夹“test”并将所有数据从 dist/browser 文件夹复制到“test”文件夹中并将 index.html 文件重命名为其他内容(例如index2.html)来解决这个问题。还使用以下行更新了 firebase.json 文件:
....
"hosting": {
"public": "test",
....
Run Code Online (Sandbox Code Playgroud)
因此,每当输入 URL 时,firebase 都会搜索公共文件夹中的 index.html 文件,如果不存在 index.html 文件,它将调用我们的云函数。
| 归档时间: |
|
| 查看次数: |
1152 次 |
| 最近记录: |