1
0
mirror of https://github.com/actix/actix-website synced 2024-12-03 20:22:13 +01:00
actix-website/examples/url-dispatch/src/dhandler.rs

25 lines
625 B
Rust
Raw Normal View History

2019-06-26 00:20:36 +02:00
use actix_web::{guard, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
2019-06-17 08:08:42 +02:00
2020-09-12 17:21:54 +02:00
#[allow(dead_code)]
2019-12-28 20:10:02 +01:00
async fn index(_req: HttpRequest) -> impl Responder {
2019-06-17 08:08:42 +02:00
"Welcome!"
}
2018-05-24 19:13:55 +02:00
2019-06-17 08:08:42 +02:00
// <default>
2020-09-12 17:21:54 +02:00
#[actix_web::main]
2019-12-28 20:10:02 +01:00
async fn main() -> std::io::Result<()> {
2019-06-26 00:20:36 +02:00
HttpServer::new(|| {
App::new()
.service(web::resource("/").route(web::get().to(index)))
.default_service(
web::route()
.guard(guard::Not(guard::Get()))
.to(|| HttpResponse::MethodNotAllowed()),
)
})
2020-09-12 17:21:54 +02:00
.bind("127.0.0.1:8080")?
2019-06-26 00:20:36 +02:00
.run()
2019-12-28 20:10:02 +01:00
.await
2018-05-24 19:13:55 +02:00
}
// </default>