Skip to content

Commit e1e45e1

Browse files
Create config.rst
1 parent e202b3d commit e1e45e1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

web/config.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)