1
0
mirror of https://github.com/actix/actix-website synced 2025-06-29 08:14:58 +02:00

Updates 'autoreloading' section

This commit is contained in:
Cameron Dershem
2019-06-17 00:44:38 -04:00
parent 3f95205696
commit 312031a085
4 changed files with 32 additions and 27 deletions

View File

@ -40,33 +40,7 @@ listenfd = "0.3"
Then modify your server code to only invoke `bind` as a fallback:
```rust
extern crate actix_web;
extern crate listenfd;
use listenfd::ListenFd;
use actix_web::{server, App, HttpRequest, Responder};
fn index(_req: &HttpRequest) -> impl Responder {
"Hello World!"
}
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() {
server.listen(l)
} else {
server.bind("127.0.0.1:3000").unwrap()
};
server.run();
}
```
{{< include-example example="autoreload" file="main.rs" section="autoreload" >}}
## Running the Server