mirror of
https://github.com/actix/actix-website
synced 2024-11-27 18:12:57 +01:00
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
#![allow(dead_code)]
|
|
|
|
// <config>
|
|
use actix_web::{web, App, HttpResponse, HttpServer};
|
|
|
|
// this function could be located in a different module
|
|
fn scoped_config(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(
|
|
web::resource("/test")
|
|
.route(web::get().to(|| async { HttpResponse::Ok().body("test") }))
|
|
.route(web::head().to(HttpResponse::MethodNotAllowed)),
|
|
);
|
|
}
|
|
|
|
// this function could be located in a different module
|
|
fn config(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(
|
|
web::resource("/app")
|
|
.route(web::get().to(|| async { HttpResponse::Ok().body("app") }))
|
|
.route(web::head().to(HttpResponse::MethodNotAllowed)),
|
|
);
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| {
|
|
App::new()
|
|
.configure(config)
|
|
.service(web::scope("/api").configure(scoped_config))
|
|
.route(
|
|
"/",
|
|
web::get().to(|| async { HttpResponse::Ok().body("/") }),
|
|
)
|
|
})
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|
|
// </config>
|