1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00

review application section

This commit is contained in:
Nikolay Kim
2020-01-02 12:43:41 +06:00
parent 26c877a519
commit e71c712d16
8 changed files with 84 additions and 50 deletions

View File

@ -7,3 +7,4 @@ workspace = "../"
[dependencies]
actix-web = "2.0"
actix-rt = "1.0"
actix-service = "1.0"

View File

@ -5,11 +5,15 @@ async fn index() -> impl Responder {
"Hello world!"
}
#[rustfmt::skip]
#[actix_rt::main]
async fn main() {
App::new().service(
web::scope("/app")
.route("/index.html", web::get().to(index)));
HttpServer::new(|| {
App::new().service(
web::scope("/app").route("/index.html", web::get().to(index)),
)
})
.bind("127.0.0.1:8088")?
.run()
.await
}
// </setup>

View File

@ -0,0 +1,20 @@
// <config>
use actix_service::ServiceFactory;
use actix_web::dev::{MessageBody, ServiceRequest, ServiceResponse};
use actix_web::{web, App, Error, HttpResponse};
fn create_app() -> App<
impl ServiceFactory<
Config = (),
Request = ServiceRequest,
Response = ServiceResponse<impl MessageBody>,
Error = Error,
>,
impl MessageBody,
> {
App::new().service(
web::scope("/app")
.route("/index.html", web::get().to(|| HttpResponse::Ok())),
)
}
// </config>

View File

@ -3,20 +3,26 @@ use actix_web::{web, App, HttpResponse};
pub mod app;
pub mod combine;
pub mod config;
pub mod config_app;
pub mod scope;
pub mod state;
pub mod vh;
#[rustfmt::skip]
// <multi>
fn main() {
App::new()
.service(
web::scope("/app1")
.route("/", web::to(|| HttpResponse::Ok())))
.service(
web::scope("/app2")
.route("/", web::to(|| HttpResponse::Ok())))
.route("/", web::to(|| HttpResponse::Ok()));
#[actix_rt::main]
async fn main() {
HttpServer::new(|| {
App::new()
.service(
web::scope("/app1").route("/", web::to(|| HttpResponse::Ok())),
)
.service(
web::scope("/app2").route("/", web::to(|| HttpResponse::Ok())),
)
.route("/", web::to(|| HttpResponse::Ok()))
})
.bind("127.0.0.1:8088")?
.run()
.await
}
// </multi>

View File

@ -34,14 +34,15 @@ async fn _main() -> std::io::Result<()> {
counter: Mutex::new(0),
});
HttpServer::new(move || { // move counter into the closure
HttpServer::new(move || {
// move counter into the closure
App::new()
.app_data(counter.clone()) // <- register the created data
.route("/", web::get().to(_index))
})
.bind("127.0.0.1:8088")?
.run()
.await
.bind("127.0.0.1:8088")?
.run()
.await
}
// </make_app_mutable>