Heroku应用程序错误:应用程序中发生错误,无法为您的页面提供服务

时间:2018-10-22 11:11:40

标签: javascript html heroku dreamweaver

我正在构建一个应用程序,并且已经成功部署到HEROKU。在打开应用程序(https://odm-mobile.herokuapp.com/)时,出现应用程序错误,我使用CLI命令检查了日志,这就是我得到的:

2018-10-22T09:06:32.000000+00:00 app[api]: Build started by user aailoje@gmail.com

2018-10-22T09:06:45.572183+00:00 app[api]: Deploy 7bc663ae by user aailoje@gmail.com

2018-10-22T09:06:45.572183+00:00 app[api]: Release v24 created by user aailoje@gmail.com

2018-10-22T09:06:45.826688+00:00 heroku[web.1]: State changed from crashed to starting

2018-10-22T09:06:47.000000+00:00 app[api]: Build succeeded

2018-10-22T09:06:49.116924+00:00 heroku[web.1]: Starting process with command `npm start`

2018-10-22T09:06:53.099327+00:00 app[web.1]:

2018-10-22T09:06:53.099345+00:00 app[web.1]: > odm-mobile@1.0.0 start /app

2018-10-22T09:06:53.099347+00:00 app[web.1]: > node index.js

2018-10-22T09:06:53.099349+00:00 app[web.1]:

2018-10-22T09:06:53.840102+00:00 heroku[web.1]: Process exited with status 0

2018-10-22T09:06:53.856482+00:00 heroku[web.1]: State changed from starting to crashed

2018-10-22T09:06:53.858384+00:00 heroku[web.1]: State changed from crashed to starting

2018-10-22T09:06:57.152906+00:00 heroku[web.1]: Starting process with command `npm start`

2018-10-22T09:07:00.298331+00:00 app[web.1]:

2018-10-22T09:07:00.298348+00:00 app[web.1]: > odm-mobile@1.0.0 start /app

2018-10-22T09:07:00.298350+00:00 app[web.1]: > node index.js

2018-10-22T09:07:00.298351+00:00 app[web.1]:

2018-10-22T09:07:00.979144+00:00 heroku[web.1]: Process exited with status 0

2018-10-22T09:07:00.997278+00:00 heroku[web.1]: State changed from starting to crashed

2018-10-22T09:07:20.183091+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=odm-mobile.herokuapp.com request_id=c9a8b164-2f61-459b-87da-56518ce4dc81 fwd="154.120.97.254" dyno= connect= service= status=503 bytes= protocol=https

2018-10-22T09:07:22.293716+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=odm-mobile.herokuapp.com request_id=6870b281-7607-4882-8bac-e97c38169e26 fwd="154.120.97.254" dyno= connect= service= status=503 bytes= protocol=https

2018-10-22T09:25:14.164205+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=odm-mobile.herokuapp.com request_id=af0d9ab3-8a64-494e-8b2e-4b5e0a46f7fd fwd="154.120.97.254" dyno= connect= service= status=503 bytes= protocol=https

2018-10-22T09:25:15.783603+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=odm-mobile.herokuapp.com request_id=dcd6cc6f-0959-4ca7-b4d4-43143e952b8c fwd="154.120.97.254" dyno= connect= service= status=503 bytes= protocol=https`

以下是我在Dreamweaver上使用的文件

  1. index.js

    var port = Number(process.env.PORT|| 5000);
    var express = require('express'),
        moment = require('moment');
    
    var exports = module.exports = function(dir, options) {
        var modules = {};
        options = merge(options || {}, {
            lazy: true
        });
    
        fs.readdirSync(dir).forEach(function(filename) {
            // filter index and dotfiles
            if (filename !== 'index.js' && filename[0] !== '.') {
                var moduleName = path.basename(filename, path.extname(filename));
                var modulePath = path.join(dir, moduleName);
                // lazy load
                if (options.lazy) {
                    Object.defineProperty(modules, moduleName, {
                        get: function() {
                            return require(modulePath);
                        }
                    });
                } else {
                    modules[moduleName] = require(modulePath);
                }
            }
        });
    
        return modules;
    };

  2. package.json

    {
      "name": "odm-mobile",
      "version": "1.0.0",
      "description": "odm daily devotional",
      "main": "index.js",
      "scripts": {
        "start": "node index.js"
      },
      "keywords": [],
      "author": "xdoshent <aailoje@gmail.com>",
      "license": "MIT",
      "repository": {
        "type": "git",
        "url": "odm-mobile"
      },
      "dependencies": {
        "@fortawesome/fontawesome-free": "^5.4.1",
        "express": "^4.16.4",
        "index.js": "0.0.3",
        "moment": "^2.22.2",
        "packages": "0.0.8"
      },
      "engines": {
        "node": "8.12.0",
        "engines": {
          "npm": "6.4.1"
        }
      }
    }

  3. 过程文件

    web: node index.js

请清楚指出我可能遇到的问题以及正在使用的文件中的错误,因为我是所有这些新手

1 个答案:

答案 0 :(得分:1)

Heroku不是FaaS服务,而是PaaS。我看到您已经导出了一个函数,但是到此为止。确保您正在运行长时间运行的应用程序,即守护程序。如日志中明确指出的那样,您的应用程序不等待任何内容,而是直接返回返回代码0退出,这表明程序已成功完成执行。我不是Node.js开发人员,但看看ExpressJS的Hello World示例将最有可能帮助您了解为什么这次这次不起作用。

https://expressjs.com/en/starter/hello-world.html


app.listen(port, () => console.log(`Example app listening on port ${port}!`))

此行完成ExpressJS的代码片段中的工作。它开始监听传入的连接,因此永远阻塞直到被杀死并接受连接。