我正在尝试在Heroku上运行Angular应用程序。我已经阅读了许多指南,但是解决方案不适用于我的情况。在Heroku上应用程序构建成功。但是,当应用程序启动时,会发生错误。
package.json
{
"name": "angular-heroku",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"postinstall": "ng build --aot --prod",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.1.3",
"@angular/common": "~9.1.3",
"@angular/compiler": "~9.1.3",
"@angular/core": "~9.1.3",
"@angular/forms": "~9.1.3",
"@angular/platform-browser": "~9.1.3",
"@angular/platform-browser-dynamic": "~9.1.3",
"@angular/router": "~9.1.3",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.3",
"@angular/cli": "~9.1.3",
"@angular/compiler-cli": "~9.1.3",
"@angular/language-service": "~9.1.3",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3"
}
}
server.js
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist/angular-heroku'));
app.post('/*', function(req, res){
res.sendFile(__dirname + '/dist/angular-heroku/index.html');
});
app.listen(4200);
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AngularHeroku</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
hello
<app-root></app-root>
</body>
</html>
app.component.html
world
我只需要有关如何在Heroku上运行示例Angular 9应用程序(可能是Angular 8)的代码示例。请帮助:(
您可以做的是...
git clone https://github.com/xyz/angular.git
cd angular
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
当您使用第4条命令推送项目时,将自动安装所有依赖项。在此之前,您的项目应上传到github。