Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaredlockhart/d987d90659f19e4dedeff4b5519c8c56 to your computer and use it in GitHub Desktop.
Save jaredlockhart/d987d90659f19e4dedeff4b5519c8c56 to your computer and use it in GitHub Desktop.
jkerim@jkerim-mbp~/Documents/rust-todo/api(master)$ docker run -it todo sh
# cat src/main.rs
extern crate actix_web;
extern crate listenfd;
use listenfd::ListenFd;
use actix_web::{server, App, HttpRequest, Responder};
fn index(_req: &HttpRequest) -> impl Responder {
"Fast start"
}
fn main() {
let mut listenfd = ListenFd::from_env();
let mut server = server::new(|| {
App::new()
.resource("/", |r| r.f(index))
});
server = if let Some(l) = listenfd.take_tcp_listener(0).unwrap() {
println!("listen?");
server.listen(l)
} else {
println!("bind?");
server.bind("0.0.0.0:3000").unwrap()
};
println!("Running on 0.0.0.0:3000");
server.run();
}# cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.20s
# cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.19s
Running `target/debug/rust-todo`
Hello, world!
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment