成功部署了带有Heroku代理的Angular应用程序,但网页显示“找不到错误”

时间:2018-11-29 06:15:05

标签: node.js angular heroku

我已经像往常一样部署了我的角度应用程序,但是这次我遇到了“未发现错误”。当我检查Heroku日志时,以下消息引人注目...

 Error: ENOENT: no such file or directory, stat '/app/dist/my-app/index.html'

我的server.js文件看起来像这样...

const express = require('express');
const app = express();
const path = require('path');

app.use(express.static(__dirname + '/dist/my-app'));
app.listen(process.env.PORT || 8080);

app.get('/*', (req, res) => {
   res.sendFile(path.join(__dirname + '/dist/my-app/index.html'));
});

console.log('Node-express server listening!');

我像往常一样将@angluar/cli@angular/compiler-cli以及typescript从devDependencies移到了依赖对象中。这是我的package.json ..

{
  "name": "my-app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "node server.js --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "ng build --aot --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.0.4",
    "@angular/cdk": "^7.0.4",
    "@angular/cli": "^7.0.6",
    "@angular/common": "^7.0.4",
    "@angular/compiler": "^7.0.4",
    "@angular/compiler-cli": "^7.0.4",
    "@angular/core": "^7.0.4",
    "@angular/flex-layout": "^7.0.0-beta.19",
    "@angular/forms": "^7.0.4",
    "@angular/http": "^7.0.4",
    "@angular/material": "^7.0.4",
    "@angular/platform-browser": "^7.0.4",
    "@angular/platform-browser-dynamic": "^7.0.4",
    "@angular/router": "^7.0.4",
    "core-js": "^2.5.7",
    "express": "^4.16.4",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "ngx-gallery": "^5.9.0",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "typescript": "^3.1.6",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.10.6",
    "@angular/language-service": "^7.0.4",
    "@types/jasmine": "~3.3.0",
    "@types/jasminewd2": "~2.0.6",
    "@types/node": "~10.12.9",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^2.0.4",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "^5.4.1",
    "ts-node": "~7.0.1",
    "tslint": "~5.11.0"
  },
  "engines": {
    "node": "10.10.0",
    "npm": "6.4.1"
  }
}

这次唯一的区别是在scripts对象中,我有"start": "node server.js"而不是通常的"start": "node server.js --proxy-config proxy.conf.json"

项目在本地编译并以“开始” "ng serve --proxy-config proxy.conf.json"运行。

我还依次通过heroku run bashdir检查了所有丢失的文件或文件夹。一切似乎都很好。

我之前已经多次构建并部署了角度应用程序到heroku。我这次可以找到的唯一区别是,我正在使用代理连接到后端。难道我做错了什么?任何帮助都很好。

0 个答案:

没有答案