繁体   English   中英

简单的API.AI node.js webhook在Heroku上崩溃

[英]Simple API.AI node.js webhook crashes on Heroku

我尝试着为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"
  }
}

搜索日志后,我找到了正确的设置。

这是正确的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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM