maciejhirsz / kobold

Easy declarative web interfaces.
https://docs.rs/kobold/
Mozilla Public License 2.0
385 stars 7 forks source link

ERR_CONNECTION_REFUSED when running on remote server #18

Closed ltfschoen closed 1 year ago

ltfschoen commented 1 year ago

If I run this on my local machine which is macOS by following the README.md instructions by installing Rust and running:

git clone https://github.com/maciejhirsz/kobold
cd kobold
cargo install --locked trunk
rustup target add wasm32-unknown-unknown
cd examples/hello_world
trunk serve

Then it outputs server listening at http://127.0.0.1:8080 And when I go to http://127.0.0.1:8080 in my web browser it displays: Hello Kobold!

However, if I try to run it on a remote machine. The output said server listening at http://127.0.0.1:8080 But when I went to view the website in my web browser by going to http://127.0.0.1:8080, but it returned error ERR_CONNECTION_REFUSED. So I instead I found the IP address of the remote server I was running Kobold on, which was , and went to http://:8080, but it also returned error ERR_CONNECTION_REFUSED. So I went through the process of checking if I had a firewall blocking port 8080, but I didn't. So then I tried running a different web server on port 8080 by running npx -y http-server in the examples/hello_world/dist/ directory, which output:

Starting up http-server, serving ./

http-server version: 14.1.1

http-server settings: 
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none

Available on:
  http://127.0.0.1:8080
  http://<REMOTE_IP_ADDRESS>:8080

And when I opened http://:8080 in my web browser it displayed: Hello Kobold! But I don't want to have to run a JS server to access Kobold, so then I thought it may require a custom Trunk server configuration. So I ran trunk serve --help, and found there was an --address option So I ran trunk serve --address <REMOTE_IP_ADDRESS> and then when I opened http://:8080 in my web browser it displayed: Hello Kobold! And when I ran curl -v http://<REMOTE_IP_ADDRESS>:8080 from a different browser tab, it responded with the HTML. However when I ran curl -v http://127.0.0.1:8080 it refused to connect.

On my local machine if I ran trunk serve --open it automatically opened http://127.0.0.1:8080 in my browser, but if I ran trunk serve --address <REMOTE_IP_ADDRESS> --open on my remote machine via ssh, whilst it ran the server, it also output: ERROR error opening browser error=Custom { kind: Other, error: "gio: http://<REMOTE_IP_ADDRESS>:8080/: Operation not supported (exit status: 2)" }

Suggest updating the README.md instructions to mention how to handle remote machine usage. Also need to figure out how to run Trunk so that it's served on both 127.0.0.1 (localhost) + remote IP at the same time

maciejhirsz commented 1 year ago

This is kind of confusing. For one this is more of a Trunk issue than Kobold, but even then you probably don't want to use Trunk as a server in production. I suppose you can configure it to bind to 0.0.0.0 instead of 127.0.0.1 for it to be accessible remotely, but it really only should used for its intended purpose: as a dev server with hot reloading on code changes.