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:
@ -7,3 +7,4 @@ workspace = "../"
|
||||
[dependencies]
|
||||
actix-web = "2.0"
|
||||
actix-rt = "1.0"
|
||||
actix-service = "1.0"
|
||||
|
@ -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>
|
||||
|
20
examples/application/src/config_app.rs
Normal file
20
examples/application/src/config_app.rs
Normal 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>
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user