2016-07-22 4 views
2

私はAngular 2 Universalを使用してアプリケーションを実装するためのチュートリアルに従っています。 Herokuの上で私は角度2 Universal Heroku Deploy

at=error code=H10 desc="App crashed" method=GET path="/" 

とserver.tsを取得しています、私は周りを探してきたし、この問題への答えを見つけることができません

// the polyfills must be the first thing imported in node.js 
import 'angular2-universal/polyfills'; 

import * as path from 'path'; 
import * as express from 'express'; 
import * as bodyParser from 'body-parser'; 
import * as cookieParser from 'cookie-parser'; 

// Angular 2 
import { enableProdMode } from '@angular/core'; 
// Angular 2 Universal 
import { expressEngine } from 'angular2-universal'; 

// enable prod for faster renders 
enableProdMode(); 

const app = express(); 
const ROOT = path.join(path.resolve(__dirname, '..')); 

// Express View 
app.engine('.html', expressEngine); 
app.set('views', __dirname); 
app.set('view engine', 'html'); 

app.use(cookieParser('Angular 2 Universal')); 
app.use(bodyParser.json()); 

// Serve static files 
app.use('/assets', express.static(path.join(__dirname, 'assets'), {maxAge: 30})); 
app.use(express.static(path.join(ROOT, 'dist/client'), {index: false})); 


import { serverApi } from './backend/api'; 
// Our API for demos only 
app.get('/data.json', serverApi); 

import { ngApp } from './main.node'; 
// Routes with html5pushstate 
// ensure routes match client-side-app 
app.get('/', ngApp); 
app.get('/about', ngApp); 
app.get('/about/*', ngApp); 
app.get('/home', ngApp); 
app.get('/home/*', ngApp); 
app.get('/ourwork', ngApp); 
app.get('/ourwork/*', ngApp); 
app.get('/services', ngApp); 
app.get('/services/*', ngApp); 
app.get('/portfolio', ngApp); 
app.get('/portfolio/*', ngApp); 
app.get('/contact', ngApp); 
app.get('/contact/*', ngApp); 

// use indexFile over ngApp only when there is too much load on the server 
function indexFile(req, res) { 
    // when there is too much load on the server just send 
    // the index.html without prerendering for client-only 
    res.sendFile('/index.html', {root: __dirname}); 
} 

app.get('*', function(req, res) { 
    res.setHeader('Content-Type', 'application/json'); 
    var pojo = { status: 404, message: 'No Content' }; 
    var json = JSON.stringify(pojo, null, 2); 
    res.status(404).send(json); 
}); 

// Server 
app.listen(3000,() => { 
    console.log('Listening on: http://localhost:3000'); 
}); 

です。どんな助けでも大歓迎です。

答えて

2

は、使用してみてください:

// Server 
app.listen((process.env.PORT || 3000),() => { 
    console.log('Listening on port %d', this.address().port); 
}); 

代わり

// Server 
app.listen(3000,() => { 
    console.log('Listening on: http://localhost:3000'); 
}); 

の代わりにハードコード3000

+0

のHerokuのことで、特定のポートを使用するには、私はこの行を追加残念なことにとき、応答をありがとうコードの私はHerokuで次のエラーを取得し始めました。オブジェクトの__webpack_require__(/app/dist/server/index.js:21:30)にあります。 (/app/dist/server/index.js:53:21)、__webpack_require__(/app/dist/server/index.js:21:30)で、これらのエラーをAngular 2ユニバーサルスターターパック? – TyAnthoney

+0

私はあなたからの新しいエラーを本当に理解していません。あなたの質問にそれらを追加できますか? – acdcjunior

+0

このコメントは無視してください^^私の解決策は、私の開発者の依存関係が私の依存関係とは異なることでした。ありがとうございます – TyAnthoney