Как оформить мой угловой проект в героку? - PullRequest
0 голосов
/ 10 марта 2019

Я следую этому учебнику о том, как развернуть угловой проект в heroku, но для меня это не работает, это просто простое новое приложение my-app, проект работает нормально в моем регионе, но в сбой героку, это сервер.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(__dirname + '/dist/<name-of-app>'));

app.get('/*', function(req,res) {

res.sendFile(path.join(__dirname+'/dist/<name-of-app>/index.html'));
});

// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 80);

ошибка, которую я получаю, заключается в следующем в логах от heroku.

    Build started by user *******

    2019-03-09T12:40:39.881315+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=client-platon.herokuapp.com request_id=de6958cf-3dc6-46c9-9184-447d07fc1 fwd="177.049.203.292" dyno= connect= service= status=503 bytes= protocol=https

    2019-03-09T12:41:08.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/a2cd5214-2a58-4f1d-a20d-06af1d704234/activity/builds/545bbf7f-e1e0-451f-8faa-b5e8c9ff1543

2019-03-09T16:27:21.608342+00:00 app[web.1]: npm ERR! platon@0.0.0 start: `node server.js`

Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...

    2019-03-09T16:27:21.606643+00:00 app[web.1]: npm ERR! errno 1

    2019-03-09T16:27:21.608342+00:00 app[web.1]: npm ERR! platon@0.0.0 start: `node server.js`

Я установил экспресс-модуль и следую всем инструкциям.

packagge json file

{
  "name": "platon",
  "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",
    "heroku-postbuild": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/cli": "^7.3.5",
    "@angular/compiler-cli": "^7.2.8",
    "@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",
    "core-js": "^2.5.4",
    "express": "^4.16.4",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26",
    "typescript": "~3.2.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "^7.3.5",
    "@angular/compiler-cli": "^7.2.8",
    "@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": "10.14.1",
    "npm": "6.7.0"
  }
}

1 Ответ

0 голосов
/ 10 марта 2019

Нужно внести некоторые изменения, которые я вижу. В файле server.js введите название вашего приложения insted _dirName И в package.json, + Изменить "postinstall": "ng build --aot —-prod",

Это просто —- прод. Попробуйте, и вы можете следовать этому уроку.

https://medium.com/@hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147

...