我在heroku中部署了angular4应用程序。
但是当我去打开应用程序时它会出错。应用程序不是构建和打开。
2017-07-26T08:19:59.741829+00:00 app[web.1]: > node server.js
2017-07-26T08:19:59.741830+00:00 app[web.1]:
2017-07-26T08:20:01.797312+00:00 heroku[web.1]: State changed from starting to up
2017-07-26T08:20:04.642127+00:00 heroku[router]: at=info method=GET path="/" host=infinite-citadel-72017.herokuapp.com request_id=f96e6b85-c5d8-48f2-8099-fb8001724ef6 fwd="103.62.141.34" dyno=web.1 connect=1ms service=27ms status=404 bytes=360 protocol=https
2017-07-26T08:21:05.520827+00:00 heroku[router]: at=info method=GET path="/" host=infinite-citadel-72017.herokuapp.com request_id=b044ae56-69ad-4af1-84bf-21bf00d9706f fwd="103.62.141.34" dyno=web.1 connect=0ms service=4ms status=404 bytes=360 protocol=https
2017-07-26T08:21:06.205476+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=infinite-citadel-72017.herokuapp.com request_id=5ff717d1-8ebe-403a-88e9-277478540e5e fwd="103.62.141.34" dyno=web.1 connect=0ms service=2ms status=404 bytes=371 protocol=https
2017-07-26T08:34:29.309746+00:00 heroku[router]: at=info method=GET path="/" host=infinite-citadel-72017.herokuapp.com request_id=f8d540bd-6acf-4c24-b4cc-50de416f7810 fwd="103.62.141.34" dyno=web.1 connect=0ms service=2ms status=404 bytes=360 protocol=https
2017-07-26T09:09:13.853930+00:00 heroku[web.1]: Idling
2017-07-26T09:09:13.854616+00:00 heroku[web.1]: State changed from up to down
2017-07-26T09:09:14.365925+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-07-26T09:09:14.547790+00:00 heroku[web.1]: Process exited with status 143
请帮我解决这个问题。
答案 0 :(得分:1)
我找到了解决问题的方法。如果试图在heroku上构建项目,那么它会给出错误。在heroku上部署后,需要在localhost上构建。并将其链接到dist文件夹。
server.js:
var express = require('express');
var path = require('path');
var app = express();
app.use(express.static(path.join(__dirname, 'dist')));
var port = process.env.PORT || '4000';
app.set('port', port);
var server = app.listen(port);
console.log('listening on port 4000');
的package.json:
{
"name": "angular-io-example",
"version": "1.0.0",
"private": true,
"description": "Example project from an angular.io guide.",
"scripts": {
"test:once": "karma start karma.conf.js --single-run",
"build": "rimraf dist && webpack --config config/webpack.prod.js --bail",
"serve": "lite-server -c=bs-config.json",
"predev": "npm run build",
"start": "node server.js",
"dev": "webpack-dev-server",
"pretest": "npm run build",
"test": "karma start karma.webpack.conf.js",
"pretest:once": "npm run build",
"build:watch": "tsc -p src/ -w",
"build:upgrade": "tsc",
"serve:upgrade": "http-server",
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
"serve:aot": "lite-server -c bs-config.aot.json",
"build:babel": "babel src -d src --extensions \".es6\" --source-maps",
"copy-dist-files": "node ./copy-dist-files.js",
"i18n": "ng-xi18n",
"lint": "tslint ./src/**/*.ts -t verbose",
"ng": "ng",
"e2e": "ng e2e"
}