我正在尝试通过以下方法在Heroku服务器上部署angular应用程序。 https://medium.com/@hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147
如果有人对此有任何想法,请在我试图找出此错误的根源时帮助我。在此先感谢
我将-prod更改为--prod,这帮助我成功地部署了该应用程序,但是,在打开该应用程序时,它给了我“” not found error“”,并且控制台错误是无法加载资源:服务器响应状态为404(未找到)。
这是应用程序的链接 https://recipebook-angularapp.herokuapp.com/
此应用程序可以在我的本地服务器上完美运行。
这是我的package.json
{
"name": "recipe-book",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot -prod"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.2.0",
"@angular/cli": "~7.2.2",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/compiler-cli": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"bootstrap": "^3.4.0",
"core-js": "^2.5.4",
"express": "^4.16.4",
"path": "^0.12.7",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"typescript": "~3.2.2",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.12.0",
"@angular/cli": "~7.2.2",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "~7.2.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"enhanced-resolve": "^3.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
},
"engines": {
"node": "11.6.0",
"npm": "6.5.0"
}
}
和server.js
//Install express server
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static('./dist/recipe-book'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname,'/dist/recipe-book/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);