File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ use actix_web::{web, App, HttpResponse, HttpServer};
2+
3+ // this function could be located in a different module
4+ fn scoped_config(cfg: &mut web::ServiceConfig) {
5+ cfg.service(
6+ web::resource("/test")
7+ .route(web::get().to(|| async { HttpResponse::Ok().body("test") }))
8+ .route(web::head().to(HttpResponse::MethodNotAllowed)),
9+ );
10+ }
11+
12+ // this function could be located in a different module
13+ fn config(cfg: &mut web::ServiceConfig) {
14+ cfg.service(
15+ web::resource("/app")
16+ .route(web::get().to(|| async { HttpResponse::Ok().body("app") }))
17+ .route(web::head().to(HttpResponse::MethodNotAllowed)),
18+ );
19+ }
20+
21+ #[actix_web::main]
22+ async fn main() -> std::io: :Result<()> {
23+ HttpServer::new(|| {
24+ App::new()
25+ .configure(config)
26+ .service(web::scope("/api").configure(scoped_config))
27+ .route(
28+ "/",
29+ web::get().to(|| async { HttpResponse::Ok().body("/") }),
30+ )
31+ })
32+ .bind(("127.0.0.1", 8080))?
33+ .run()
34+ .await
35+ }
You can’t perform that action at this time.
0 commit comments