Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将angular项目部署到heroku_Angular_Heroku_Deployment - Fatal编程技术网

将angular项目部署到heroku

将angular项目部署到heroku,angular,heroku,deployment,Angular,Heroku,Deployment,我正在尝试将angular项目部署到heroku。我执行了所有步骤并得到错误: 加载资源失败:服务器响应状态为503(服务不可用)favicon。ico:1。是代码中的问题,还是我在heroku站点上设置错误 { "name": "flashcards", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng start", "build": "ng build", "test": "ng

我正在尝试将angular项目部署到heroku。我执行了所有步骤并得到错误: 加载资源失败:服务器响应状态为503(服务不可用)favicon。ico:1。是代码中的问题,还是我在heroku站点上设置错误

{
  "name": "flashcards",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng start",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "preinstall": "npm install -g @angular/cli",
    "postinstall": "ng build --aot --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.13",
    "@angular/cdk": "^8.2.3",
    "@angular/cli": "^8.3.17",
    "@angular/common": "~8.2.5",
    "@angular/compiler": "~8.2.5",
    "@angular/compiler-cli": "^8.2.13",
    "@angular/core": "~8.2.5",
    "@angular/forms": "~8.2.5",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.5",
    "@angular/platform-browser-dynamic": "~8.2.5",
    "@angular/router": "~8.2.5",
    "@types/crypto-js": "^3.1.43",
    "crypto-js": "^3.1.9-1",
    "express": "^4.17.1",
    "hammerjs": "^2.0.8",
    "jwt-token-encrypt": "^1.0.4",
    "material-design-icons": "^3.0.1",
    "path": "^0.12.7",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "typescript": "~3.5.3",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.4",
    "@angular/cli": "^8.3.17",
    "@angular/compiler-cli": "^8.2.13",
    "@angular/language-service": "~8.2.5",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "enhanced-resolve": "^3.3.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  },
  "engines": {
    "node": "10.16.0",
    "npm": "6.9.0"
  }
}
我正在尝试将angular项目部署到heroku。我执行了所有步骤并得到错误:
加载资源失败:服务器响应状态为503(服务不可用)favicon。ico:1。是代码中的问题,还是我在heroku站点上设置错误

Heroku需要一台express服务器,以便在生产模式下运行Angular应用程序。在Angular应用程序的根文件夹中打开命令窗口。执行以下命令以安装express server

{
  "name": "flashcards",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng start",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "preinstall": "npm install -g @angular/cli",
    "postinstall": "ng build --aot --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.13",
    "@angular/cdk": "^8.2.3",
    "@angular/cli": "^8.3.17",
    "@angular/common": "~8.2.5",
    "@angular/compiler": "~8.2.5",
    "@angular/compiler-cli": "^8.2.13",
    "@angular/core": "~8.2.5",
    "@angular/forms": "~8.2.5",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.5",
    "@angular/platform-browser-dynamic": "~8.2.5",
    "@angular/router": "~8.2.5",
    "@types/crypto-js": "^3.1.43",
    "crypto-js": "^3.1.9-1",
    "express": "^4.17.1",
    "hammerjs": "^2.0.8",
    "jwt-token-encrypt": "^1.0.4",
    "material-design-icons": "^3.0.1",
    "path": "^0.12.7",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "typescript": "~3.5.3",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.4",
    "@angular/cli": "^8.3.17",
    "@angular/compiler-cli": "^8.2.13",
    "@angular/language-service": "~8.2.5",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "enhanced-resolve": "^3.3.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  },
  "engines": {
    "node": "10.16.0",
    "npm": "6.9.0"
  }
}
npm install express --save
在项目文件夹中创建server.js文件:-

const express = require('express');
const app = express();
const path = require('path');
const port = process.env.PORT || 4200;
const server = require('http').Server(app);


// Serve only the static files form the angularapp directory
app.use(express.static(__dirname + '/your-application-name'));
 
app.get('/*', function(req,res) {
 
res.sendFile(path.join(__dirname+'/your-application-name/index.html'));
});
 
// Start the app by listening on the default Heroku port


server.listen(port, function () {
    console.log("App running on port " + port);
})
更新package.json文件中的脚本

"start": "node server.js",
"postinstall": "ng build --output-path your-application-name --aot --prod",

确保.gitignore文件中未提及dist文件。

您有时可以通过在单独的终端窗口中运行
heroku logs-t,然后尝试再次启动应用程序来诊断问题。据我所知,对于无法在heroku中启动的应用程序,这是一个非常普遍的错误。