1
0
mirror of https://github.com/actix/actix-website synced 2024-11-27 18:12:57 +01:00

Update autoreload example to v2

This commit is contained in:
Yuki Okushi 2019-12-29 01:21:10 +09:00
parent 299ee6e352
commit 1e5f5ecf8b
2 changed files with 8 additions and 6 deletions

View File

@ -4,5 +4,6 @@ version = "1.0.0"
edition = "2018"
[dependencies]
actix-web = "1.0"
actix-web = "2.0"
actix-rt = "1.0"
listenfd = "0.3"

View File

@ -2,20 +2,21 @@
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use listenfd::ListenFd;
fn index(_req: HttpRequest) -> impl Responder {
async fn index(_req: HttpRequest) -> impl Responder {
"Hello World!"
}
fn main() {
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
let mut listenfd = ListenFd::from_env();
let mut server = HttpServer::new(|| App::new().route("/", web::get().to(index)));
server = if let Some(l) = listenfd.take_tcp_listener(0).unwrap() {
server.listen(l).unwrap()
server.listen(l)?
} else {
server.bind("127.0.0.1:3000").unwrap()
server.bind("127.0.0.1:3000")?
};
server.run().unwrap();
server.run().await
}
// </autoreload>