【问题标题】:Simple API.AI node.js webhook crashes on Heroku简单的 API.AI node.js webhook 在 Heroku 上崩溃
【发布时间】:2017-07-21 13:35:07
【问题描述】:

我尝试为 Google 的 NLP API.AI 接口实现一个简单的 webhook。我想使用 Heroku 作为使用 node.js 的服务器。问题是我可以在 Heroku 上构建和部署代码,但执行立即失败。

从构建日志中提取(注意“实名”应用未测试,我只是为这篇文章更改了它)

[...]
2017-07-21T13:28:57.000000+00:00 app[api]: Build succeeded
2017-07-21T13:29:07.012028+00:00 heroku[web.1]: Starting process with command `npm start`
2017-07-21T13:29:10.516218+00:00 app[web.1]: 
2017-07-21T13:29:10.516234+00:00 app[web.1]: > test@0.0.3 start /app
2017-07-21T13:29:10.516235+00:00 app[web.1]: > node app.js
2017-07-21T13:29:10.516236+00:00 app[web.1]: 
2017-07-21T13:29:11.076809+00:00 heroku[web.1]: State changed from starting to crashed

我已经尝试了许多不同版本的代码,但即使是这个被简化为几乎什么都没有的代码也无法执行。

这是我的 app.js:

'use strict';

 process.env.DEBUG = 'actions-on-google:*';
 const ApiAiApp = require('actions-on-google').ApiAiApp;

 const test = function(request, response) {
 // todo
};

module.exports = {
  test
};

这是 package.json 文件:

{
  "name": "test",
  "description": "virtual scrum master",
  "version": "0.0.3",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "scripts": {
    "lint": "semistandard --fix \"**/*.js\"",
    "start": "node app.js",
    "monitor": "nodemon app.js",
    "deploy": "gcloud app deploy"
  },
  "engines": {
    "node": "6.11.1"
  },
  "dependencies": {
    "actions-on-google": "^1.0.0"    
  },
  "devDependencies": {
    "semistandard": "^9.1.0"
  }
}

【问题讨论】:

    标签: javascript node.js heroku webhooks dialogflow-es


    【解决方案1】:

    经过一番搜索,我找到了正确的设置。

    这是正确的 app.js 代码:

    'use strict';
    
    process.env.DEBUG = 'actions-on-google:*';
    let Assistant = require('actions-on-google').ApiAiAssistant;
    let bodyParser = require('body-parser');
    
    let app = express();
    app.use(bodyParser.json({type: 'application/json'}));
    
    app.post('/', function (req, res) {
    
    // Todo
    
    });
    
    if (module === require.main) {
      // Start the server
      let server = app.listen(process.env.PORT || 8080, function () {
        let port = server.address().port;
        console.log('App listening on port %s', port);
      });
    }
    
    module.exports = app;
    

    【讨论】:

      猜你喜欢
      • 2012-05-02
      • 2018-03-08
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      相关资源
      最近更新 更多