ERR_CONNECTION_REFUSED Angular 站点部署到 Firebase 托管后(localhost...?)

ERR_CONNECTION_REFUSED after Angular site deployed to Firebase Hosting (localhost...?)

我正在尝试评估来自 angular-templates.io 的管理模板,并且生产构建工作正常。我上传到 Firebase 托管指定 dist/browser(在生产构建期间创建)但是当我在浏览器中加载 firebase 应用程序时,它只显示 "Loading..."。它给出的错误是:

main.43059628ad5e08be77bb.js:1 ERROR Error: Uncaught (in promise): [object Undefined] at R (polyfills.45eead93d001664270af.js:1) at R (polyfills.45eead93d001664270af.js:1) at polyfills.45eead93d001664270af.js:1 at t.invokeTask (polyfills.45eead93d001664270af.js:1) at Object.onInvokeTask (main.43059628ad5e08be77bb.js:1) at t.invokeTask (polyfills.45eead93d001664270af.js:1) at e.runTask (polyfills.45eead93d001664270af.js:1) at d (polyfills.45eead93d001664270af.js:1) at e.invokeTask [as invoke] (polyfills.45eead93d001664270af.js:1) at _ (polyfills.45eead93d001664270af.js:1)

vp @ main.43059628ad5e08be77bb.js:1 localhost:8000/assets/data/ng2_charts.json:1 Failed to load resource: net::ERR_CONNECTION_REFUSED

main.43059628ad5e08be77bb.js:1 ERROR Error: Uncaught (in promise): [object Undefined] at R (polyfills.45eead93d001664270af.js:1) at R (polyfills.45eead93d001664270af.js:1) at polyfills.45eead93d001664270af.js:1 at t.invokeTask (polyfills.45eead93d001664270af.js:1) at Object.onInvokeTask (main.43059628ad5e08be77bb.js:1) at t.invokeTask (polyfills.45eead93d001664270af.js:1) at e.runTask (polyfills.45eead93d001664270af.js:1) at d (polyfills.45eead93d001664270af.js:1) at e.invokeTask [as invoke] (polyfills.45eead93d001664270af.js:1) at _ (polyfills.45eead93d001664270af.js:1) vp @ main.43059628ad5e08be77bb.js:1

localhost:8000/assets/data/extended_table.json:1 Failed to load resource: net::ERR_CONNECTION_REFUSED

似乎是说找不到两个文件:ng2_charts.json & extended_table.json at localhost:8000/assets/data。这两个文件确实存在于 dist/browser/assets/data 下,但为什么要搜索 localhost?

我在文档中没有看到任何关于在部署前需要更改配置的信息,我按照 angular-templates.io

中的说明进行了操作

这实际上是我执行的每个步骤:

npm i -g @angular/cli 

从下载的 zip 中复制源文件(在属性中勾选解锁后)

npm i
npm audit fix
npm run build:ssr && npm run serve:ssr

创建 dist/browser 文件夹并正常运行

npm i @angular/fire firebase --save
npm i angularfire2
npm install -g firebase-tools
firebase init
firebase deploy

在浏览器中打开 firebase 应用程序

我好像漏掉了一个配置步骤,但我没有在任何地方的文档中看到它。任何帮助将不胜感激!

我检查了 SO 以尝试找到答案,但这些是我找到的最接近的答案:

My react project not working after deploy to firebase hosting

Angular not displaying firestore data when deployed

想通了!必须更新两个文件(server.tssrc\environments\environment.prod.ts

server.ts 来自

app.listen(PORT, () => {
   console.log(`Node Express server listening on http://localhost:${PORT}`);
});

app.listen(PORT, () => {
   console.log(`Node Express server listening on https://<myfirebaseproject>.firebaseapp.com:${PORT}`);
});

src\environments\environment.prod.ts

来自

exports.environment = {
   production: true,
   BASE_URL: 'http://mylocalhost:8008'
};

exports.environment = {
   production: true,
   BASE_URL: 'https://<myfirebaseproject>.firebaseapp.com'
};

如果记录在案,有人可以发表评论以供我参考吗?如果 angular-templates.io 提到它会很有帮助。