loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
5.45k stars 235 forks source link

fix: devcontainer interface binding #995

Open endrl opened 3 days ago

endrl commented 3 days ago

Add interface binding to the config.

Tested

closes: https://github.com/loco-rs/loco/issues/677 Requires: https://github.com/loco-rs/loco-devcontainer/pull/1

jondot commented 2 days ago

@endrl thanks for this PR! also thanks for adjusting and updating the base_template, i'm happy you found it. this change is hard to accept since NODE_BINDING is not a universal thing -- is there a different way to achieve what you're trying to solve?

endrl commented 1 day ago

Thank you for you fast response, i tinkered a little bit and this is what i noticed in docker

# with interface localhost <-- broken port forward
 sudo netstat -tulpn | grep LISTEN
tcp        0      0 127.0.0.11:39899        0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:45457         0.0.0.0:*               LISTEN      258/node            
tcp6       0      0 ::1:5150                :::*                    LISTEN      1572/target/debug/s 

# with interface 0.0.0.0 <-- works
sudo netstat -tulpn | grep LISTEN
tcp        0      0 0.0.0.0:5150            0.0.0.0:*               LISTEN      1772/target/debug/s 
tcp        0      0 127.0.0.11:46355        0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:38659         0.0.0.0:*               LISTEN      258/node   

# with interface 127.0.0.1 <-- works
sudo netstat -tulpn | grep LISTEN
tcp        0      0 127.0.0.1:5150          0.0.0.0:*               LISTEN      1788/target/debug/s 
tcp        0      0 127.0.0.11:43631        0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:44405         0.0.0.0:*               LISTEN      258/node 

A strange ipv6 bind is going on with localhost. I don't know why, especially there is no ipv6 network. The node port forward that devcontainer uses is a syscall to 127.0.0.1:PORT. But 127.0.0.1 is not reachable when loco binds to localhost

The vs code docs recommends to bind to 0.0.0.0.

Possible solutions

I think the devcontainer setup should work out of the box, i was trapped because of the following config comment

 # Port on which the server will listen. the server binding is 0.0.0.0:{PORT}

This might be also a docker bug... If you look at the docs of appPort Edit: Found https://github.com/docker/for-mac/issues/7269