node.js - 当用户通过输入 URL 直接访问时,具有 Firebase Cloud 功能的 Angular SSR 始终返回 404
问题描述
我按照这个链接创建了一个带有 Firebase 云功能的 Angular SSR链接
firebase.json
{
"hosting": [
{
"target": "myproject",
"public": "dist/myproject/browser",
"ignore": [
"**/.*"
],
"headers": [
{
"source": "*.[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].+(css|js)",
"headers": [
{
"key": "Cache-Control",
"value": "public,max-age=31536000,immutable"
}
]
}
],
"rewrites": [
{
"source": "**",
"destination": "ssr" <-- My cloud function name
}
]
}
],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
函数/index.ts
import * as functions from 'firebase-functions';
const regionalFunctions = functions.region('asia-east2');
const universal = require(`${process.cwd()}/dist/myproject/server/main`).app();
export const ssr = regionalFunctions.https.onRequest(universal);
通过运行firebase serve
命令,在我的本地机器上进行测试
i hosting[myproject]: Serving hosting files from: dist/smyproject/browser
✔ hosting[myproject]: Local server: http://localhost:5000
✔ functions[asia-east2-ssr]: http function initialized (http://localhost:5001/myproject/asia-east2/ssr).
在我的本地机器上,当我输入 http://localhost:5000
或类似的http://localhost:5000/some/path/in-my-angular-routing
东西会被重定向到我的默认页面时它工作正常
但是当我ng deploy
在生产中使用命令和测试时,如果我输入 https://myproject-id.web.app
或类似的东西 https://myproject-id.web.app/some/path/in-my-angular-routing
,它总是会返回 404。
我该如何解决这个问题?
解决方案
推荐阅读
- ios - 添加 URL 地址时如何检测 Internet 浏览器文本字段
- c# - Powershell 脚本作为 Topshelf/Windows 服务
- javascript - 隐藏角度材料中的重复列数据
- sed - 如何在另一个文件中用 HTML 实体替换 UTF-8 字符?
- python - 新手问题 - 将函数分成两部分
- python - Pytest:在 setup_method 中使用固定装置
- python - 在 Python 中使用用户输入结束循环
- javascript - “m 未定义” discord.js 消息收集器
- swift - 抓取保存在 Firebase 中的数据并将其呈现在视图控制器上
- php - PHP XSLTProcessor 去除样式属性和标签