【问题标题】:Node.js Route.post()Node.js 路由.post()
【发布时间】:2019-07-20 04:34:22
【问题描述】:

我正在编写一个 Node.js 应用程序,我正在尝试使用我的 index.js 文件中的函数。每当我添加

var IndexBot = require('/root/afstudeerwerk/chatbotPIROS/index');

对于我的 calls.js 文件,我收到以下错误: 错误1:

routes.js (/root/afstudeerwerk/chatbotApi/api/routes):

'use strict';
module.exports = function(app) {
var chatbot = require('/root/afstudeerwerk/chatbotPIROS/calls');

app.post('/slack/receive',chatbot.create_a_message);
app.post('/DBcheck/:id',chatbot.checkUserAuth);
};

calls.js (/root/afstudeerwerk/chatbotPIROS/calls)

'use strict';
exports.create_a_message = function(req, res) {
var IndexBot = require('/root/afstudeerwerk/chatbotPIROS/index');
var message = req.body;

var button = JSON.parse(message.payload).actions[0].value

if(button == 'MeanMakeVM'){
        res.json({message:'Please enter your VM specs.'});
        IndexBot.stuur_bot_bericht('dit is een testbericht.');
}

【问题讨论】:

    标签: node.js function object npm callback


    【解决方案1】:

    您的控制器中缺少任何您在路由文件文件中为其指定路由的方法。

    在您的路由文件中,您有一个路由 app.post('/DBcheck/:id',chatbot.checkUserAuth);,但它在 calls.js 中没有任何名为 checkUserAuth 的函数,这就是它给您错误的原因。

    在调用文件中创建一个名为 checkUserAuth 的方法,您的错误将得到解决

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 2017-07-11
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多