2

I'm running this hello world example:

https://rocket.rs/v0.4/guide/quickstart/#running-examples

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 1.32s
     Running `C:\Users\m3\repos\Rocket\target\debug\hello_world.exe`
Configured for development.
    => address: localhost
    => port: 8000
    => log: normal
    => workers: 8
    => secret key: generated
    => limits: forms = 32KiB
    => keep-alive: 5s
    => read timeout: 5s
    => write timeout: 5s
    => tls: disabled
Mounting /:
    => GET / (hello)
Rocket has launched from http://localhost:8000

The code is available here:

https://github.com/SergioBenitez/Rocket/tree/v0.4/examples/hello_world

Problem

The problem is it only launches from http://localhost:8000. It doesn't work for http://127.0.0.1:8000 or http://192.168.1.250:8000.

Question

How can I modify the code to make the server launch from 127.0.0.1 or the static IP address of the server i.e. 192.168.1.250? I examined the code, but couldn't figure out how.

Didn't work

Modifying Cargo.toml config and adding address and port:

[global]
address = "0.0.0.0"
port = 80
Megidd
  • 7,089
  • 6
  • 65
  • 142

1 Answers1

3

A quick glance at the documentation mention a file named rocket.toml

Try to put the configuration in a file named Rocket.toml

[global]
address = "0.0.0.0"
port = 80

or for IPv6 (which should accept IPv4 too)

[global]
address = "::"
port = 80
Simson
  • 3,373
  • 2
  • 24
  • 38
  • 1
    Just commenting here that this only works for IPv4. For IPv6 reachable servers, set `address` to `"::"`. The `"::"` value works for both IPv4 and IPv6. – Kaspar Poland Jun 11 '23 at 01:21
  • I have not tested the suggestion from @KasparPoland but it sounds reasonable – Simson Jun 12 '23 at 00:36