node.js - Heroku 部署应用程序错误

标签 node.js heroku

我正在尝试部署我用 Express 和 Node 编写的 API。我尝试通过连接到 Github 和使用 Heroku Toolbelt 来部署它。两种方式都可以在日志中显示应用程序已成功部署,但我转到该页面,它总是 says :

Application Error

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

我用web:nodeindex.js创建了一个Procfile

这是我的 package.jsonindex.js 文件中的代码:

package.json:

{
  "name": "timestamp-microservice",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "edward-hong",
  "repository": {
    "type": "git",
    "url": "https://github.com/edward-hong/timestamp-microservice.git"
  },
  "license": "ISC",
  "engines": {
    "node": "4.4.0"
  },
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "body-parser": "^1.15.1",
    "express": "^4.13.4",
    "moment": "^2.13.0"
  }
}

index.js:

var express = require('express');
var bodyParser = require('body-parser');
var moment = require('moment');
var port = process.env.PORT || 3000;
var app = express();
var timeRouter = express.Router();
timeRouter.use(bodyParser.json());
timeRouter.route('/:time')
  .get(function(req, res, next){
    var time = req.params.time;
    var unixTime = Number(time);
    if (unixTime){
      res.json({'unix': unixTime, 'natural': moment.unix(unixTime).format('MMMM D, YYYY')});
    } else {
      if (moment(time).isValid()){
        res.json({'unix': Number(moment(time).format('X')), 'natural': moment(time).format('MMMM D, YYYY')});
      } else {
        res.json({'unix': null, 'natural': null});
      }
    }
  });
app.use('/', timeRouter);
app.use(express.static(__dirname, 'index.html'));
app.listen(port, function(){
  console.log('Server running at http://oursite:' + port);
});

以下是日志:

2016-05-14T09:28:27.238579+00:00 heroku[web.1]: Process exited with status 1
2016-05-14T09:28:47.111767+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=eh-timestamp-microservice.herokuapp.com request_id=4fe2d06a-8476-4e70-9b0d-c88c68f9f6b1 fwd="163.47.236.3" dyno= connect= service= status=503 bytes=
2016-05-14T09:28:48.422607+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=eh-timestamp-microservice.herokuapp.com request_id=80b36992-82a7-4938-8a2e-4e0abec86663 fwd="163.47.236.3" dyno= connect= service= status=503 bytes=
2016-05-14T09:39:28.089591+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-14T09:39:29.564906+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-05-14T09:39:32.277699+00:00 app[web.1]: /app/node_modules/express/node_modules/serve-static/index.js:47
2016-05-14T09:39:32.277742+00:00 app[web.1]:   var opts = Object.create(options || null)
2016-05-14T09:39:32.277760+00:00 app[web.1]:                     ^
2016-05-14T09:39:32.277770+00:00 app[web.1]:
2016-05-14T09:39:32.277795+00:00 app[web.1]: TypeError: Object prototype may only be an Object or null: index.html
2016-05-14T09:39:32.277798+00:00 app[web.1]:     at Function.serveStatic [as static] (/app/node_modules/express/node_modules/serve-static/index.js:47:21)
2016-05-14T09:39:32.277797+00:00 app[web.1]:     at Function.create (native)
2016-05-14T09:39:32.277798+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:23:23)
2016-05-14T09:39:32.277799+00:00 app[web.1]:     at Module._compile (module.js:409:26)
2016-05-14T09:39:32.277802+00:00 app[web.1]:     at startup (node.js:139:18)
2016-05-14T09:39:32.277812+00:00 app[web.1]:     at node.js:968:3
2016-05-14T09:39:32.277800+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-05-14T09:39:32.277799+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-05-14T09:39:32.277800+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-05-14T09:39:32.277801+00:00 app[web.1]:     at Function.Module.runMain (module.js:441:10)
2016-05-14T09:39:33.321097+00:00 heroku[web.1]: Process exited with status 1
2016-05-14T09:39:33.343282+00:00 heroku[web.1]: State changed from starting to crashed
2016-05-14T09:40:18.797349+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=eh-timestamp-microservice.herokuapp.com request_id=a351f860-7b5c-4ce7-a3b3-65fbb419b44f fwd="91.121.64.34" dyno= connect= service= status=503 bytes=
2016-05-14T09:40:19.725084+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=eh-timestamp-microservice.herokuapp.com request_id=9627bc3a-51e0-470d-8a19-60dfda8df6b2 fwd="51.255.122.75" dyno= connect= service= status=503 bytes=
2016-05-14T09:43:03.346097+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=eh-timestamp-microservice.herokuapp.com request_id=da725ac8-1aa6-4801-b33c-875395c97f8f fwd="122.171.196.55" dyno= connect= service= status=503 bytes=
2016-05-14T09:43:05.023995+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=eh-timestamp-microservice.herokuapp.com request_id=3e13f96b-4605-4b12-891f-d2add65e32a6 fwd="122.171.196.55" dyno= connect= service= status=503 bytes=
2016-05-14T09:43:55.572621+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/?123" host=eh-timestamp-microservice.herokuapp.com request_id=e4142733-b39e-44da-964d-b2507c7fdfd6 fwd="122.171.196.55" dyno= connect= service= status=503 bytes=
2016-05-14T09:43:55.958412+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=eh-timestamp-microservice.herokuapp.com request_id=597b272e-dd2b-4646-a099-1ca009bb49c7 fwd="122.171.196.55" dyno= connect= service= status=503 bytes=
2016-05-14T09:43:57.833280+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/123" host=eh-timestamp-microservice.herokuapp.com request_id=4a33ecea-5813-4c8d-9a21-a1a089170120 fwd="122.171.196.55" dyno= connect= service= status=503 bytes=
2016-05-14T09:43:58.247554+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=eh-timestamp-microservice.herokuapp.com request_id=1561f774-9d38-4003-b37e-29392bc962ac fwd="122.171.196.55" dyno= connect= service= status=503 bytes=
2016-05-14T09:49:27.982002+00:00 heroku[api]: Release v10 created by edward.hong527@gmail.com
2016-05-14T09:49:27.982002+00:00 heroku[api]: Deploy 182e72e by edward.hong527@gmail.com
2016-05-14T09:49:28.148769+00:00 heroku[slug-compiler]: Slug compilation started
2016-05-14T09:49:28.148779+00:00 heroku[slug-compiler]: Slug compilation finished
2016-05-14T09:49:28.171518+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-14T09:49:29.761171+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-05-14T09:49:31.808646+00:00 app[web.1]: /app/node_modules/express/node_modules/serve-static/index.js:47
2016-05-14T09:49:31.808665+00:00 app[web.1]:   var opts = Object.create(options || null)
2016-05-14T09:49:31.808666+00:00 app[web.1]:                     ^
2016-05-14T09:49:31.808668+00:00 app[web.1]: TypeError: Object prototype may only be an Object or null: index.html
2016-05-14T09:49:31.808667+00:00 app[web.1]:
2016-05-14T09:49:31.808669+00:00 app[web.1]:     at Function.create (native)
2016-05-14T09:49:31.808669+00:00 app[web.1]:     at Function.serveStatic [as static] (/app/node_modules/express/node_modules/serve-static/index.js:47:21)
2016-05-14T09:49:31.808670+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:23:23)
2016-05-14T09:49:31.808670+00:00 app[web.1]:     at Module._compile (module.js:409:26)
2016-05-14T09:49:31.808671+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-05-14T09:49:31.808672+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-05-14T09:49:31.808672+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-05-14T09:49:31.808673+00:00 app[web.1]:     at Function.Module.runMain (module.js:441:10)
2016-05-14T09:49:31.808673+00:00 app[web.1]:     at startup (node.js:139:18)
2016-05-14T09:49:31.808674+00:00 app[web.1]:     at node.js:968:3
2016-05-14T09:49:32.501619+00:00 heroku[web.1]: Process exited with status 1
2016-05-14T09:49:32.536377+00:00 heroku[web.1]: State changed from starting to crashed
2016-05-14T09:49:38.856013+00:00 heroku[slug-compiler]: Slug compilation started
2016-05-14T09:49:38.856024+00:00 heroku[slug-compiler]: Slug compilation finished
2016-05-14T09:49:38.704760+00:00 heroku[api]: Deploy 182e72e by edward.hong527@gmail.com
2016-05-14T09:49:38.704788+00:00 heroku[api]: Release v11 created by edward.hong527@gmail.com
2016-05-14T09:49:38.918627+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-14T09:49:39.993466+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-05-14T09:49:42.145320+00:00 app[web.1]: /app/node_modules/express/node_modules/serve-static/index.js:47
2016-05-14T09:49:42.145342+00:00 app[web.1]:   var opts = Object.create(options || null)
2016-05-14T09:49:42.145344+00:00 app[web.1]:                     ^
2016-05-14T09:49:42.145345+00:00 app[web.1]:
2016-05-14T09:49:42.145346+00:00 app[web.1]: TypeError: Object prototype may only be an Object or null: index.html
2016-05-14T09:49:42.145346+00:00 app[web.1]:     at Function.create (native)
2016-05-14T09:49:42.145347+00:00 app[web.1]:     at Function.serveStatic [as static] (/app/node_modules/express/node_modules/serve-static/index.js:47:21)
2016-05-14T09:49:42.145348+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:23:23)
2016-05-14T09:49:42.145348+00:00 app[web.1]:     at Module._compile (module.js:409:26)
2016-05-14T09:49:42.145349+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-05-14T09:49:42.145350+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-05-14T09:49:42.145350+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-05-14T09:49:42.145351+00:00 app[web.1]:     at Function.Module.runMain (module.js:441:10)
2016-05-14T09:49:42.145352+00:00 app[web.1]:     at startup (node.js:139:18)
2016-05-14T09:49:42.145352+00:00 app[web.1]:     at node.js:968:3
2016-05-14T09:49:42.929388+00:00 heroku[web.1]: State changed from starting to crashed
2016-05-14T09:49:42.909282+00:00 heroku[web.1]: Process exited with status 1
2016-05-14T09:50:05.626329+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=eh-timestamp-microservice.herokuapp.com request_id=cdee94cc-a0bf-4907-b442-1e72a09d1e20 fwd="163.47.236.3" dyno= connect= service= status=503 bytes=
2016-05-14T09:50:07.477549+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=eh-timestamp-microservice.herokuapp.com request_id=88cbbbca-5afc-4740-a934-751718040503 fwd="163.47.236.3" dyno= connect= service= status=503 bytes=
2016-05-14T09:55:36.623731+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-14T09:55:37.903604+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-05-14T09:55:39.780790+00:00 app[web.1]: /app/node_modules/express/node_modules/serve-static/index.js:47
2016-05-14T09:55:39.780809+00:00 app[web.1]:   var opts = Object.create(options || null)
2016-05-14T09:55:39.780810+00:00 app[web.1]:                     ^
2016-05-14T09:55:39.780810+00:00 app[web.1]:
2016-05-14T09:55:39.780811+00:00 app[web.1]: TypeError: Object prototype may only be an Object or null: index.html
2016-05-14T09:55:39.780811+00:00 app[web.1]:     at Function.create (native)
2016-05-14T09:55:39.780812+00:00 app[web.1]:     at Function.serveStatic [as static] (/app/node_modules/express/node_modules/serve-static/index.js:47:21)
2016-05-14T09:55:39.780812+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:23:23)
2016-05-14T09:55:39.780813+00:00 app[web.1]:     at Module._compile (module.js:409:26)
2016-05-14T09:55:39.780813+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-05-14T09:55:39.780813+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-05-14T09:55:39.780814+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-05-14T09:55:39.780814+00:00 app[web.1]:     at Function.Module.runMain (module.js:441:10)
2016-05-14T09:55:39.780814+00:00 app[web.1]:     at startup (node.js:139:18)
2016-05-14T09:55:39.780815+00:00 app[web.1]:     at node.js:968:3
2016-05-14T09:55:40.461214+00:00 heroku[web.1]: State changed from starting to crashed
2016-05-14T09:55:40.440635+00:00 heroku[web.1]: Process exited with status 1
2016-05-14T09:59:58.706941+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=eh-timestamp-microservice.herokuapp.com request_id=9fe4e275-f9e0-49df-bc6f-a90395578d35 fwd="163.47.236.3" dyno= connect= service= status=503 bytes=
2016-05-14T09:59:59.785150+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=eh-timestamp-microservice.herokuapp.com request_id=59101524-ec76-4742-9b6f-77003bf0ab0f fwd="163.47.236.3" dyno= connect= service= status=503 bytes=
2016-05-14T10:00:18.450815+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=eh-timestamp-microservice.herokuapp.com request_id=42c2b2aa-a549-48db-bebd-734f910b2f94 fwd="42.236.50.154" dyno= connect= service= status=503 bytes=
2016-05-14T10:07:05.926172+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=eh-timestamp-microservice.herokuapp.com request_id=05d5ab32-ba20-428f-9886-4baae5456bc9 fwd="182.118.35.23" dyno= connect= service= status=503 bytes=

我想知道如何将其成功部署到 Heroku 上?

最佳答案

静态中间件采用两个参数,一个是要服务的目录的根路径的字符串,以及一个选项对象。

例如

serveStatic('public/ftp', {'index': ['default.html', 'default.htm']})

在您的情况下,第二个参数是一个字符串,这是不正确的。

关于node.js - Heroku 部署应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37225055/

相关文章:

node.js - 从中间件访问环回配置数据

android - 使用 Volley 在 Android 中从 http 迁移到 https

node.js - 自定义 Yeoman 生成器的 npm 测试失败

javascript - Boolean(x) 和 !!x 之间的区别

javascript - 在 Express.js 中从 UInt8Array 发送二进制响应

node.js - 为在 phantomjs 中的 browserify 包上运行(通过 grunt)的 Jasmine 测试生成 Istanbul 尔代码覆盖率报告

heroku - spymemchached 是否已预加载到 heroku tomcat 实例上?

node.js - 使用 Codeship 进行持续部署

ruby-on-rails - 部署到 heroku 时关系不存在

ruby-on-rails - 在 Heroku 上的 Rails 中一次显示大量记录