简体   繁体   中英

EHOSTUNREACH error while sending HTTP request from Hubot to Rails app locally

I am developing a Slack bot (using Hubot ) as well as a Rails app that will receive HTTP requests from it and process them accordingly. Basically, the high-level steps of what I want to do are like this:

  1. A slack user sends a trigger word to the bot (let's say the trigger is "bye").
  2. Hubot picks up the trigger, then sends a request to the Rails app.
  3. Rails app marks the Slack user as out of office.

I seem to have some sort of routing issue, because I get the EHOSTUNREACH error when I try to execute this flow with both apps booted ( rails s for Rails and ./bin/hubot --adapter slack for Hubot). I'm guessing that Hubot is unable to reach the Rails app at all. Am I missing something here? What URL do I need to use to enable these apps to send requests to each other?

I've also tried swapping out the 127.0.0.1:3000 with localhost:3000 , but the results stayed the same.

Hubot code

module.exports = (robot) ->
  robot.respond /bye/i, (res) ->
    res.reply('Later alligator')
    robot.logger.info 'Will proceed to clock out user'

    data = JSON.stringify({
      slack_user_id: res.message.user.id
    })
    robot.http("127.0.0.1:3000/")
      .header('Content-Type', 'application/json')
      .post(data) (err, resp, body) ->
        if err
          robot.logger.info "Encountered an error: #{err}"
        else
          robot.logger.info 'Successfully sent HTTP request to Rails app'

Log results when I send trigger word to bot

INFO Will proceed to clock out user
INFO Encountered an error: Error: connect EHOSTUNREACH 0.0.11.184:80 - Local (192.168.91.168:60029)

Rails server log (it's definitely port 3000)

* Listening on tcp://localhost:3000

将请求更改为robot.http("http://localhost:3000")确保您在开始时拥有协议。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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