2015-07-12 34 views
0

最近我一直在使用Node.js創建一個聊天應用程序,並且當我在heroku上託管它時,它會不斷彈出這個錯誤。我的代碼可以找到here。我相信這是與端口不被動態分配有關,但在這個設置中我該如何做到這一點?在節點JS中動態分配端口

2015-07-12T11:00:35.931639+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-spire-4645.herokuapp.com request_id=1d5bbae1-6fcc-42cf-b987-d17b45a3ef96 fwd="101.184.151.145" dyno= connect= service= status=503 bytes=

回答

1

您需要綁定的港口到港口環境變量(這讓由Heroku上設置的端口)。

當你正在設置在你的配置文件中的端口,你可以使用這樣的事情:

var config = JSON.parse(fs.readFileSync('./config.json')) 

var port = process.env.PORT || config.port; 

var server = new ws.Server({host: config.host, port: port})