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

ngrok Cannot GET / local server up and running

不过,我正在尝试关注 Crowdbotics' Messenger bot tutorial。我完全按照他提到的那样做了,但我明白了。

我的文件夹:

好的,首先我 运行 node index.js 得到以下内容:

紧接着。我们通过 ngrok http 5000 初始化我们的 ngrok 服务器并得到以下内容:

但是在每个 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'));

我真的不能指出我做错了什么,非常感谢您的帮助。

根据您的 express js 代码,我认为您还没有定义到“/”的路由

在 index.js 文件的 app.listen 之前添加此内容

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

您的 index.js 已经启动了一个侦听和响应 HTTP 协议的服务器 - 但它 "serve files" 与 Apache 等网络服务器的方式不同。

正如@Yana 指出的那样,您需要明确设置一个路由来执行某些操作,例如发回文本响应。

如果您希望在请求时发送 favicon.ico 文件,那么您需要为此设置一个 static route 作为 index.js 代码的一部分。