gpt4 book ai didi

node.js - robots.router 和 robots.http 有什么区别?

转载 作者:太空宇宙 更新时间:2023-11-04 00:11:18 24 4
gpt4 key购买 nike

我继承了一个coffeescript hubot应用程序。除了自述文件和教程之外,我找不到论坛或任何其他问题的答案,所以我在这里提问。

我用谷歌搜索了这个问题,但找不到答案。

robot.router和robot.http有什么区别?两者似乎都采用 get、put、delete 等和 URL。我的应用程序同时使用这两种方法,但在我看来,我看不出其中的区别。

看起来路由器正在运行express,而http是自制的。这对客户端来说有语义上的差异吗?

最佳答案

我也很难找到好的文档,但设法从 Hubot Scripting doc 中获得了一些见解。 。如果您在页面中搜索“robot.router”和“robot.http”,您将遇到以下定义:

机器人.http

这用于对其他 Web 服务进行 HTTP 调用(类似于 jQuery AJAXAxios)

Hubot can make HTTP calls on your behalf to integrate & consume third party APIs. This can be through an instance of node-scoped-http-client available at robot.http. The simplest case looks like:

robot.http("https://midnight-train")   
.get() (err, res, body) ->
# your code here

机器人.路由器

这是一个Express服务器。它是一个 HTTP 监听器,用于接受和响应 HTTP 请求

Hubot includes support for the express web framework to serve up HTTP requests. It listens on the port specified by the EXPRESS_PORT or PORT environment variables (preferred in that order) and defaults to 8080. An instance of an express application is available at robot.router. It can be protected with username and password by specifying EXPRESS_USER and EXPRESS_PASSWORD. It can automatically serve static files by setting EXPRESS_STATIC.

The most common use of this is for providing HTTP end points for services with webhooks to push to, and have those show up in chat.

module.exports = (robot) ->
# the expected value of :room is going to vary by adapter, it
# might be a numeric id, name, token, or some other value
robot.router.post '/hubot/chatsecrets/:room', (req, res) ->
room = req.params.room
data = if req.body.payload? then JSON.parse req.body.payload else req.body
secret = data.secret
robot.messageRoom room, "I have a secret: #{secret}"
res.send 'OK'

关于node.js - robots.router 和 robots.http 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49416502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com