1
0
mirror of https://github.com/actix/actix-website synced 2024-12-02 19:52:23 +01:00
actix-website/examples/autoreload/src/main.rs

23 lines
570 B
Rust
Raw Normal View History

2019-06-17 06:44:38 +02:00
// <autoreload>
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use listenfd::ListenFd;
2019-12-28 17:21:10 +01:00
async fn index(_req: HttpRequest) -> impl Responder {
2019-06-17 06:44:38 +02:00
"Hello World!"
}
2019-12-28 17:21:10 +01:00
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-06-17 06:44:38 +02:00
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() {
2019-12-28 17:21:10 +01:00
server.listen(l)?
2019-06-17 06:44:38 +02:00
} else {
2019-12-28 17:21:10 +01:00
server.bind("127.0.0.1:3000")?
2019-06-17 06:44:38 +02:00
};
2019-12-28 17:21:10 +01:00
server.run().await
2019-06-17 06:44:38 +02:00
}
// </autoreload>