mitsuhiko / systemfd

Development helper utility for helping with auto reloading for projects supporting systemd socket activation
Apache License 2.0
468 stars 17 forks source link

what's the port to listen #5

Open leoliuxd opened 5 years ago

leoliuxd commented 5 years ago
use listenfd::ListenFd;
use actix_web::{server, App, Path};

fn index(info: Path<(String, u32)>) -> String {
   format!("Hello {}! id:{}", info.0, info.1)
}

fn main() {
    let mut listenfd = ListenFd::from_env();
    let mut server = server::new(
        || App::new()
            .resource("/{name}/{id}/index.html", |r| r.with(index)));
    server = if let Some(listener) = listenfd.take_tcp_listener(0).unwrap() {
        server.listen(listener)
    } else {
        server.bind("127.0.0.1:3000").unwrap()
    };
    server.run();
}

server.listen(listener) so what's the port ? Is is always 80?

ricochet1k commented 5 years ago

The port is picked up from the systemfd command, so it's whatever you pass to the -s flag. For example, if you do systemfd -s 80 -- ./your_server, then it will use port 80.