mirror of
https://github.com/actix/actix-website
synced 2024-11-24 00:41:07 +01:00
Update autoreload example to v2
This commit is contained in:
parent
299ee6e352
commit
1e5f5ecf8b
@ -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"
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user