muety / telegram-expense-bot

A bot that helps you manage and track your daily expenses.
59 stars 16 forks source link

Webhook mode not working #40

Closed elite-sheep closed 9 months ago

elite-sheep commented 9 months ago

Hi there, I am trying to set up this bot on my server with Caddy. I am doing the following things:

I give PUBLIC_URL as domain.com/subdomain and let the bot listen on port 3010. After that I change the caddy file and forward all posts to that URL to port 3010, like the following:

domain.com/subdomain/* {
        reverse_proxy localhost:3010
}

Then I restarted caddy, start the bot. However, the bot is not working. I checked the caddy status log and I find the following:

Sep 27 17:01:46 dragon2 caddy[109799]: {"level":"error","ts":1695834106.1660464,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:3010: connect: connection refused","request":{"remote_ip":"91.108.6.126","remote_port":"31578","client_ip":"91.108.6.>
Sep 27 17:02:05 dragon2 caddy[109799]: {"level":"error","ts":1695834125.1833286,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:3010: connect: connection refused","request":{"remote_ip":"91.108.6.126","remote_port":"32890","client_ip":"91.108.6.>

Seems the bot is not listening the port. I am not sure what happened at this moment. Can you please give some suggestions?

muety commented 9 months ago

Can you check if the bot is actually up and running? Also, please make sure that it's running at the correct IP and port (use netstat -tulpn and possibly post the output here).

elite-sheep commented 9 months ago

Yeah, I think it is listening there, I found this in the log

tcp        0      0 127.0.0.1:3010          0.0.0.0:*               LISTEN      110441/node
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -

Very strange, at the same time I found this in caddy's log:

Sep 27 17:07:50 dragon2 caddy[109799]: {"level":"error","ts":1695834470.0878074,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:3010: connect: connection refused","request":{"remote_ip":"91.108.6.126","remote_port":"29992","client_ip":"91.108.6.>
muety commented 9 months ago

Are you able to access the bot directly (on the host machine)? Try curl http://127.0.0.1:3010.

elite-sheep commented 9 months ago

I tried this before and this is my output:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>

I think I am able to access the bot? (If not the connection should be refused.)

muety commented 9 months ago

Yes, that means the bot is running properly.

I don't think that's related to your particular error message, but I think your Caddyfile will rather have to look something like this:

domain.com {
  route /subdomain* {
    uri strip_prefix /subdomain
    reverse_proxy http://localhost:3010
  }
}
elite-sheep commented 9 months ago

Yeah, that will work. Thank you! I will close this issue.