2021-12-07 15:31:15 +00:00
|
|
|
use actix_http::HttpService;
|
|
|
|
use actix_server::Server;
|
|
|
|
use actix_service::map_config;
|
2024-08-18 13:33:28 +00:00
|
|
|
use actix_web::{dev::AppConfig, get, App, Responder};
|
2021-12-07 15:31:15 +00:00
|
|
|
|
|
|
|
#[get("/")]
|
2024-08-18 13:33:28 +00:00
|
|
|
async fn index() -> impl Responder {
|
2021-12-07 15:31:15 +00:00
|
|
|
"Hello, world. From Actix Web!"
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
Server::build()
|
|
|
|
.bind("hello-world", "127.0.0.1:8080", || {
|
|
|
|
// construct actix-web app
|
|
|
|
let app = App::new().service(index);
|
|
|
|
|
|
|
|
HttpService::build()
|
|
|
|
// pass the app to service builder
|
|
|
|
// map_config is used to map App's configuration to ServiceBuilder
|
2022-03-05 23:43:31 +00:00
|
|
|
// h1 will configure server to only use HTTP/1.1
|
|
|
|
.h1(map_config(app, |_| AppConfig::default()))
|
2021-12-07 15:31:15 +00:00
|
|
|
.tcp()
|
|
|
|
})?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|