ngrok无法获取/运行本地服务器

时间:2018-10-24 18:07:17

标签: javascript node.js dialogflow facebook-messenger ngrok

但是,我正在尝试遵循Crowdbotics' Messenger bot tutorial。我照他说的做,但是我明白了。

我的文件夹:

enter image description here

好的,首先我运行node index.js并获得以下信息:

enter image description here

此后。我们通过ngrok http 5000初始化ngrok服务器,并获得以下信息:

enter image description here

但是在每个 http请求中,我得到了经典的Cannot GET /

事后看来,我的index.js仅包含:

const express = require("express");
const bodyParser = require("body-parser");

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.listen(5000, () => console.log('Webhook server is listening, port 5000'));

我不能真正指出我做错了什么,您的帮助我们将受到感激。

2 个答案:

答案 0 :(得分:2)

根据您的明确js代码,我认为您尚未定义到'/'的路由

将其添加到index.js文件上的app.listen之前

app.get('/', (req, res) => res.send('Hello World!'))

答案 1 :(得分:1)

您的index.js已启动了一个侦听并响应HTTP协议的服务器-但它不像Apache这样的Web服务器那样“提供文件”。

如@Yana所述,您需要显式设置路由以执行某些操作,例如发送回文本响应。

如果您希望在请求时发送favicon.ico文件,则需要为此index.js代码设置一个static route