Heroku节点503

时间:2018-04-07 18:03:30

标签: node.js heroku http-status-code-503

我正在创建一个非常简单的Heroku NodeJS服务器,并在加载页面时抛出以下错误:

Failed to load resource: the server responded with a status of 503 (Service Unavailable)

index.js文件的代码:

const express = require('express');
const app = express();


app.get('/', (request, res) => {
    res.send('Conneccteedd!!')
    }
)

app.get('/something', (request, res) => {
    res.send('somethingg!!')
    }
)

app.listen(3000, () => console.log('Example app listening on post 3000!'))

当我运行heroku logs时,我明白了:

2018-04-07T17:23:59.443080+00:00 app[api]: Enable Logplex by user rcocuzzo8@gmail.com
2018-04-07T17:23:59.139900+00:00 app[api]: Release v1 created by user rcocuzzo8@gmail.com
2018-04-07T17:23:59.139900+00:00 app[api]: Initial release by user rcocuzzo8@gmail.com
2018-04-07T17:23:59.443080+00:00 app[api]: Release v2 created by user rcocuzzo8@gmail.com
2018-04-07T17:24:44.000000+00:00 app[api]: Build started by user rcocuzzo8@gmail.com
2018-04-07T17:24:52.198560+00:00 app[api]: Deploy ac13e171 by user rcocuzzo8@gmail.com
2018-04-07T17:24:52.198560+00:00 app[api]: Release v3 created by user rcocuzzo8@gmail.com
2018-04-07T17:24:52.225795+00:00 app[api]: Scaled to web@1:Free by user rcocuzzo8@gmail.com
2018-04-07T17:24:44.000000+00:00 app[api]: Build succeeded
2018-04-07T17:24:54.670733+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-07T17:24:57.221082+00:00 heroku[web.1]: Process exited with status 1
2018-04-07T17:24:57.237275+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-07T17:24:57.240098+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-07T17:24:57.159083+00:00 app[web.1]: npm ERR! missing script: start
2018-04-07T17:24:57.165086+00:00 app[web.1]: 
2018-04-07T17:24:57.165114+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-04-07T17:24:57.165210+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-04-07T17_24_57_160Z-debug.log
2018-04-07T17:25:00.031630+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-07T17:25:02.926871+00:00 heroku[web.1]: Process exited with status 1
2018-04-07T17:25:02.833143+00:00 app[web.1]: npm ERR! missing script: start
2018-04-07T17:25:02.842169+00:00 app[web.1]: 
2018-04-07T17:25:02.842516+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-04-07T17:25:02.842705+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-04-07T17_25_02_835Z-debug.log
2018-04-07T17:25:02.943109+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-07T17:25:33.768543+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-crag-38927.herokuapp.com request_id=604adedc-92bb-41f9-aff8-510ef9540502 fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:25:34.409195+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-crag-38927.herokuapp.com request_id=0e875c22-57c7-4222-88b7-182580dc5aca fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:25:52.739291+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-crag-38927.herokuapp.com request_id=68de943d-1ec9-4b58-8c2a-1b02f330746c fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:25:53.528379+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-crag-38927.herokuapp.com request_id=b6b7cf31-64e7-4888-9eb9-42fe65b4f9c0 fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:27:33.130652+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-crag-38927.herokuapp.com request_id=9c3180f6-76fa-40f1-98b4-d39018991e96 fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:27:33.494007+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-crag-38927.herokuapp.com request_id=3841d1fa-d1ca-482c-8f43-947f07e4f84d fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:33:42.000000+00:00 app[api]: Build started by user rcocuzzo8@gmail.com
2018-04-07T17:33:52.608615+00:00 app[api]: Deploy 9d2bc566 by user rcocuzzo8@gmail.com
2018-04-07T17:33:52.608615+00:00 app[api]: Release v4 created by user rcocuzzo8@gmail.com
2018-04-07T17:33:42.000000+00:00 app[api]: Build succeeded
2018-04-07T17:33:54.281891+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-07T17:33:57.242836+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-07T17:33:59.949160+00:00 app[web.1]: 
2018-04-07T17:33:59.949177+00:00 app[web.1]: > first@1.0.0 start /app
2018-04-07T17:33:59.949179+00:00 app[web.1]: > node index.js
2018-04-07T17:33:59.949181+00:00 app[web.1]: 
2018-04-07T17:34:00.317195+00:00 app[web.1]: Example app listening on post 3000!
2018-04-07T17:34:57.440018+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-04-07T17:34:57.440165+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-04-07T17:34:57.554675+00:00 heroku[web.1]: Process exited with status 137
2018-04-07T17:34:57.575996+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-07T17:35:07.163337+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-crag-38927.herokuapp.com request_id=872ac12e-8d25-40c9-a6c8-304a6e8aab42 fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:35:07.584580+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-crag-38927.herokuapp.com request_id=0534531c-1a76-46a9-9fc0-54c0c814387e fwd="73.178.82.243" dyno= connect= service= status=503 bytes= protocol=https
2018-04-07T17:44:18.000000+00:00 app[api]: Build started by user rcocuzzo8@gmail.com
2018-04-07T17:44:27.830483+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-07T17:44:27.611180+00:00 app[api]: Release v5 created by user rcocuzzo8@gmail.com
2018-04-07T17:44:27.611180+00:00 app[api]: Deploy f1d3f52b by user rcocuzzo8@gmail.com
2018-04-07T17:44:18.000000+00:00 app[api]: Build succeeded
2018-04-07T17:44:29.667502+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-07T17:44:32.132423+00:00 app[web.1]: 
2018-04-07T17:44:32.132444+00:00 app[web.1]: > first@1.0.0 start /app
2018-04-07T17:44:32.132445+00:00 app[web.1]: > node index.js
2018-04-07T17:44:32.132446+00:00 app[web.1]: 
2018-04-07T17:44:32.322170+00:00 app[web.1]: Example app listening on post 3000!

它似乎指向缺少start测试,但这是我的package.json文件(包含脚本):

{
  "name": "first",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Rcuz8/express-server-01.git"
  },
  "author": "cocuzzo",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Rcuz8/express-server-01/issues"
  },
  "homepage": "https://github.com/Rcuz8/express-server-01#readme",
  "dependencies": {
    "express": "^4.16.3"
  }
}

最后,这是控制台打开时网站的样子:

如果您希望代码具有更好的视觉效果:here是GitHub

2 个答案:

答案 0 :(得分:3)

来自评论: 为什么端口3000? Heroku如何知道将流量代理到该端口?

答案 1 :(得分:0)

常量端口= process.env.PORT || 3000;

app.listen(PORT);